cdx.c (0174f5810401ae6390bfe15354346b5ea660d40c) cdx.c (fa10f413091a43f801f82b3cf484f15d6fc9266f)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * CDX bus driver.
4 *
5 * Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
6 */
7
8/*

--- 165 unchanged lines hidden (view full) ---

174 * Return: matching cdx_device_id structure or NULL if there is no match.
175 */
176static inline const struct cdx_device_id *
177cdx_match_one_device(const struct cdx_device_id *id,
178 const struct cdx_device *dev)
179{
180 /* Use vendor ID and device ID for matching */
181 if ((id->vendor == CDX_ANY_ID || id->vendor == dev->vendor) &&
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * CDX bus driver.
4 *
5 * Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
6 */
7
8/*

--- 165 unchanged lines hidden (view full) ---

174 * Return: matching cdx_device_id structure or NULL if there is no match.
175 */
176static inline const struct cdx_device_id *
177cdx_match_one_device(const struct cdx_device_id *id,
178 const struct cdx_device *dev)
179{
180 /* Use vendor ID and device ID for matching */
181 if ((id->vendor == CDX_ANY_ID || id->vendor == dev->vendor) &&
182 (id->device == CDX_ANY_ID || id->device == dev->device))
182 (id->device == CDX_ANY_ID || id->device == dev->device) &&
183 (id->subvendor == CDX_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
184 (id->subdevice == CDX_ANY_ID || id->subdevice == dev->subsystem_device) &&
185 !((id->class ^ dev->class) & id->class_mask))
183 return id;
184 return NULL;
185}
186
187/**
188 * cdx_match_id - See if a CDX device matches a given cdx_id table
189 * @ids: array of CDX device ID structures to search in
190 * @dev: the CDX device structure to match against.

--- 133 unchanged lines hidden (view full) ---

324{ \
325 struct cdx_device *cdx_dev = to_cdx_device(dev); \
326 return sysfs_emit(buf, format_string, cdx_dev->field); \
327} \
328static DEVICE_ATTR_RO(field)
329
330cdx_config_attr(vendor, "0x%04x\n");
331cdx_config_attr(device, "0x%04x\n");
186 return id;
187 return NULL;
188}
189
190/**
191 * cdx_match_id - See if a CDX device matches a given cdx_id table
192 * @ids: array of CDX device ID structures to search in
193 * @dev: the CDX device structure to match against.

--- 133 unchanged lines hidden (view full) ---

327{ \
328 struct cdx_device *cdx_dev = to_cdx_device(dev); \
329 return sysfs_emit(buf, format_string, cdx_dev->field); \
330} \
331static DEVICE_ATTR_RO(field)
332
333cdx_config_attr(vendor, "0x%04x\n");
334cdx_config_attr(device, "0x%04x\n");
335cdx_config_attr(subsystem_vendor, "0x%04x\n");
336cdx_config_attr(subsystem_device, "0x%04x\n");
337cdx_config_attr(revision, "0x%02x\n");
338cdx_config_attr(class, "0x%06x\n");
332
333static ssize_t remove_store(struct device *dev,
334 struct device_attribute *attr,
335 const char *buf, size_t count)
336{
337 bool val;
338
339 if (kstrtobool(buf, &val) < 0)

--- 32 unchanged lines hidden (view full) ---

372 ret = device_for_each_child(dev, NULL, reset_cdx_device);
373 else
374 ret = cdx_dev_reset(dev);
375
376 return ret < 0 ? ret : count;
377}
378static DEVICE_ATTR_WO(reset);
379
339
340static ssize_t remove_store(struct device *dev,
341 struct device_attribute *attr,
342 const char *buf, size_t count)
343{
344 bool val;
345
346 if (kstrtobool(buf, &val) < 0)

--- 32 unchanged lines hidden (view full) ---

379 ret = device_for_each_child(dev, NULL, reset_cdx_device);
380 else
381 ret = cdx_dev_reset(dev);
382
383 return ret < 0 ? ret : count;
384}
385static DEVICE_ATTR_WO(reset);
386
387static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
388 char *buf)
389{
390 struct cdx_device *cdx_dev = to_cdx_device(dev);
391
392 return sprintf(buf, "cdx:v%04Xd%04Xsv%04Xsd%04Xc%06X\n", cdx_dev->vendor,
393 cdx_dev->device, cdx_dev->subsystem_vendor, cdx_dev->subsystem_device,
394 cdx_dev->class);
395}
396static DEVICE_ATTR_RO(modalias);
397
380static ssize_t driver_override_store(struct device *dev,
381 struct device_attribute *attr,
382 const char *buf, size_t count)
383{
384 struct cdx_device *cdx_dev = to_cdx_device(dev);
385 int ret;
386
387 if (WARN_ON(dev->bus != &cdx_bus_type))

--- 74 unchanged lines hidden (view full) ---

462 return 0;
463}
464
465static struct attribute *cdx_dev_attrs[] = {
466 &dev_attr_remove.attr,
467 &dev_attr_reset.attr,
468 &dev_attr_vendor.attr,
469 &dev_attr_device.attr,
398static ssize_t driver_override_store(struct device *dev,
399 struct device_attribute *attr,
400 const char *buf, size_t count)
401{
402 struct cdx_device *cdx_dev = to_cdx_device(dev);
403 int ret;
404
405 if (WARN_ON(dev->bus != &cdx_bus_type))

--- 74 unchanged lines hidden (view full) ---

480 return 0;
481}
482
483static struct attribute *cdx_dev_attrs[] = {
484 &dev_attr_remove.attr,
485 &dev_attr_reset.attr,
486 &dev_attr_vendor.attr,
487 &dev_attr_device.attr,
488 &dev_attr_subsystem_vendor.attr,
489 &dev_attr_subsystem_device.attr,
490 &dev_attr_class.attr,
491 &dev_attr_revision.attr,
492 &dev_attr_modalias.attr,
470 &dev_attr_driver_override.attr,
471 NULL,
472};
473
474static const struct attribute_group cdx_dev_group = {
475 .attrs = cdx_dev_attrs,
476 .is_visible = cdx_dev_attrs_are_visible,
477};

--- 121 unchanged lines hidden (view full) ---

599 memcpy(cdx_dev->res, dev_params->res, sizeof(struct resource) *
600 dev_params->res_count);
601 cdx_dev->res_count = dev_params->res_count;
602
603 /* Populate CDX dev params */
604 cdx_dev->req_id = dev_params->req_id;
605 cdx_dev->vendor = dev_params->vendor;
606 cdx_dev->device = dev_params->device;
493 &dev_attr_driver_override.attr,
494 NULL,
495};
496
497static const struct attribute_group cdx_dev_group = {
498 .attrs = cdx_dev_attrs,
499 .is_visible = cdx_dev_attrs_are_visible,
500};

--- 121 unchanged lines hidden (view full) ---

622 memcpy(cdx_dev->res, dev_params->res, sizeof(struct resource) *
623 dev_params->res_count);
624 cdx_dev->res_count = dev_params->res_count;
625
626 /* Populate CDX dev params */
627 cdx_dev->req_id = dev_params->req_id;
628 cdx_dev->vendor = dev_params->vendor;
629 cdx_dev->device = dev_params->device;
630 cdx_dev->subsystem_vendor = dev_params->subsys_vendor;
631 cdx_dev->subsystem_device = dev_params->subsys_device;
632 cdx_dev->class = dev_params->class;
633 cdx_dev->revision = dev_params->revision;
607 cdx_dev->bus_num = dev_params->bus_num;
608 cdx_dev->dev_num = dev_params->dev_num;
609 cdx_dev->cdx = dev_params->cdx;
610 cdx_dev->dma_mask = CDX_DEFAULT_DMA_MASK;
611
612 /* Initialize generic device */
613 device_initialize(&cdx_dev->dev);
614 cdx_dev->dev.parent = dev_params->parent;

--- 120 unchanged lines hidden ---
634 cdx_dev->bus_num = dev_params->bus_num;
635 cdx_dev->dev_num = dev_params->dev_num;
636 cdx_dev->cdx = dev_params->cdx;
637 cdx_dev->dma_mask = CDX_DEFAULT_DMA_MASK;
638
639 /* Initialize generic device */
640 device_initialize(&cdx_dev->dev);
641 cdx_dev->dev.parent = dev_params->parent;

--- 120 unchanged lines hidden ---