Lines Matching +full:num +full:- +full:ids

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
16 * the FPGA program manager and the APUs. The RPU provides memory-mapped
21 * +--------------------------------------+
30 * +-----------------------------|--------+
34 * +------------------------| RPU if |----+
39 * +--------------------------------------+
41 * +---------------------|----------------+
43 * | +-----------------------+ |
45 * | +-------+ +-------+ +-------+ |
47 * | +-------+ +-------+ +-------+ |
48 * +--------------------------------------+
70 #include <linux/dma-map-ops.h>
85 static char *compat_node_name = "xlnx,versal-net-cdx";
87 static void cdx_destroy_res_attr(struct cdx_device *cdx_dev, int num);
90 * cdx_dev_reset - Reset a CDX device
93 * Return: -errno on failure, 0 on success.
98 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_dev_reset()
103 cdx_drv = to_cdx_driver(dev->driver); in cdx_dev_reset()
105 if (cdx_drv && cdx_drv->reset_prepare) in cdx_dev_reset()
106 cdx_drv->reset_prepare(cdx_dev); in cdx_dev_reset()
109 ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num, in cdx_dev_reset()
110 cdx_dev->dev_num, &dev_config); in cdx_dev_reset()
115 if (cdx_drv && cdx_drv->reset_done) in cdx_dev_reset()
116 cdx_drv->reset_done(cdx_dev); in cdx_dev_reset()
123 * reset_cdx_device - Reset a CDX device
129 * Return: -errno on failure, 0 on success.
137 * cdx_unregister_device - Unregister a CDX device
150 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_unregister_device()
152 if (cdx_dev->is_bus) { in cdx_unregister_device()
154 if (cdx_dev->enabled && cdx->ops->bus_disable) in cdx_unregister_device()
155 cdx->ops->bus_disable(cdx, cdx_dev->bus_num); in cdx_unregister_device()
158 debugfs_remove_recursive(cdx_dev->debugfs_dir); in cdx_unregister_device()
159 kfree(cdx_dev->driver_override); in cdx_unregister_device()
160 cdx_dev->driver_override = NULL; in cdx_unregister_device()
167 device_del(&cdx_dev->dev); in cdx_unregister_device()
168 put_device(&cdx_dev->dev); in cdx_unregister_device()
180 * cdx_match_one_device - Tell if a CDX device structure has a matching
192 if ((id->vendor == CDX_ANY_ID || id->vendor == dev->vendor) && in cdx_match_one_device()
193 (id->device == CDX_ANY_ID || id->device == dev->device) && in cdx_match_one_device()
194 (id->subvendor == CDX_ANY_ID || id->subvendor == dev->subsystem_vendor) && in cdx_match_one_device()
195 (id->subdevice == CDX_ANY_ID || id->subdevice == dev->subsystem_device) && in cdx_match_one_device()
196 !((id->class ^ dev->class) & id->class_mask)) in cdx_match_one_device()
202 * cdx_match_id - See if a CDX device matches a given cdx_id table
203 * @ids: array of CDX device ID structures to search in
213 cdx_match_id(const struct cdx_device_id *ids, struct cdx_device *dev) in cdx_match_id() argument
215 if (ids) { in cdx_match_id()
216 while (ids->vendor || ids->device) { in cdx_match_id()
217 if (cdx_match_one_device(ids, dev)) in cdx_match_id()
218 return ids; in cdx_match_id()
219 ids++; in cdx_match_id()
227 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_set_master()
229 int ret = -EOPNOTSUPP; in cdx_set_master()
233 if (cdx->ops->dev_configure) in cdx_set_master()
234 ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num, in cdx_set_master()
235 cdx_dev->dev_num, &dev_config); in cdx_set_master()
243 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_clear_master()
245 int ret = -EOPNOTSUPP; in cdx_clear_master()
249 if (cdx->ops->dev_configure) in cdx_clear_master()
250 ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num, in cdx_clear_master()
251 cdx_dev->dev_num, &dev_config); in cdx_clear_master()
258 * cdx_bus_match - device to driver matching callback
270 const struct cdx_device_id *ids; in cdx_bus_match() local
272 if (cdx_dev->is_bus) in cdx_bus_match()
275 ids = cdx_drv->match_id_table; in cdx_bus_match()
278 if (cdx_dev->driver_override && strcmp(cdx_dev->driver_override, drv->name)) in cdx_bus_match()
281 found_id = cdx_match_id(ids, cdx_dev); in cdx_bus_match()
290 if (!found_id->override_only) in cdx_bus_match()
292 if (cdx_dev->driver_override) in cdx_bus_match()
295 ids = found_id + 1; in cdx_bus_match()
296 found_id = cdx_match_id(ids, cdx_dev); in cdx_bus_match()
304 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_probe()
306 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_probe()
313 if (cdx->msi_domain) { in cdx_probe()
314 error = msi_setup_device_data(&cdx_dev->dev); in cdx_probe()
319 error = cdx_drv->probe(cdx_dev); in cdx_probe()
330 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_remove()
333 if (cdx_drv && cdx_drv->remove) in cdx_remove()
334 cdx_drv->remove(cdx_dev); in cdx_remove()
339 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_shutdown()
342 if (cdx_drv && cdx_drv->shutdown) in cdx_shutdown()
343 cdx_drv->shutdown(cdx_dev); in cdx_shutdown()
348 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_dma_configure()
350 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_dma_configure()
351 u32 input_id = cdx_dev->req_id; in cdx_dma_configure()
354 ret = of_dma_configure_id(dev, cdx->dev->of_node, 0, &input_id); in cdx_dma_configure()
355 if (ret && ret != -EPROBE_DEFER) { in cdx_dma_configure()
360 if (!ret && !cdx_drv->driver_managed_dma) { in cdx_dma_configure()
371 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_dma_cleanup()
373 if (!cdx_drv->driver_managed_dma) in cdx_dma_cleanup()
383 return sysfs_emit(buf, format_string, cdx_dev->field); \
401 return -EINVAL; in remove_store()
404 return -EINVAL; in remove_store()
426 return -EINVAL; in reset_store()
429 return -EINVAL; in reset_store()
431 if (cdx_dev->is_bus) in reset_store()
446 return sprintf(buf, "cdx:v%04Xd%04Xsv%04Xsd%04Xc%06X\n", cdx_dev->vendor, in modalias_show()
447 cdx_dev->device, cdx_dev->subsystem_vendor, cdx_dev->subsystem_device, in modalias_show()
448 cdx_dev->class); in modalias_show()
459 if (WARN_ON(dev->bus != &cdx_bus_type)) in driver_override_store()
460 return -EINVAL; in driver_override_store()
462 ret = driver_set_override(dev, &cdx_dev->driver_override, buf, count); in driver_override_store()
474 return sysfs_emit(buf, "%s\n", cdx_dev->driver_override); in driver_override_show()
482 struct cdx_controller *cdx = cdx_dev->cdx; in enable_store()
487 return -EINVAL; in enable_store()
489 if (enable == cdx_dev->enabled) in enable_store()
492 if (enable && cdx->ops->bus_enable) in enable_store()
493 ret = cdx->ops->bus_enable(cdx, cdx_dev->bus_num); in enable_store()
494 else if (!enable && cdx->ops->bus_disable) in enable_store()
495 ret = cdx->ops->bus_disable(cdx, cdx_dev->bus_num); in enable_store()
497 ret = -EOPNOTSUPP; in enable_store()
500 cdx_dev->enabled = enable; in enable_store()
509 return sysfs_emit(buf, "%u\n", cdx_dev->enabled); in enable_show()
519 if (!cdx_dev->is_bus) in cdx_dev_attrs_are_visible()
520 return a->mode; in cdx_dev_attrs_are_visible()
531 if (cdx_dev->is_bus) in cdx_bus_attrs_are_visible()
532 return a->mode; in cdx_bus_attrs_are_visible()
575 struct cdx_device *cdx_dev = s->private; in cdx_debug_resource_show()
579 struct resource *res = &cdx_dev->res[i]; in cdx_debug_resource_show()
590 cdx_dev->debugfs_dir = debugfs_create_dir(dev_name(&cdx_dev->dev), cdx_debugfs_dir); in cdx_device_debugfs_init()
591 if (IS_ERR(cdx_dev->debugfs_dir)) in cdx_device_debugfs_init()
594 debugfs_create_file("resource", 0444, cdx_dev->debugfs_dir, cdx_dev, in cdx_device_debugfs_init()
607 return -EINVAL; in rescan_store()
610 return -EINVAL; in rescan_store()
622 count = -EINVAL; in rescan_store()
627 if (cdx && cdx->controller_registered && cdx->ops->scan) in rescan_store()
628 cdx->ops->scan(cdx); in rescan_store()
630 put_device(&pd->dev); in rescan_store()
664 cdx_driver->driver.owner = owner; in __cdx_driver_register()
665 cdx_driver->driver.bus = &cdx_bus_type; in __cdx_driver_register()
667 error = driver_register(&cdx_driver->driver); in __cdx_driver_register()
670 cdx_driver->driver.name, error); in __cdx_driver_register()
680 driver_unregister(&cdx_driver->driver); in cdx_driver_unregister()
698 * cdx_mmap_resource - map a CDX resource into user memory space
714 int num = (unsigned long)attr->private; in cdx_mmap_resource() local
718 res = &cdx_dev->res[num]; in cdx_mmap_resource()
719 if (iomem_is_exclusive(res->start)) in cdx_mmap_resource()
720 return -EINVAL; in cdx_mmap_resource()
723 size = ((cdx_resource_len(cdx_dev, num) - 1) >> PAGE_SHIFT) + 1; in cdx_mmap_resource()
724 if (vma->vm_pgoff + vma_pages(vma) > size) in cdx_mmap_resource()
725 return -EINVAL; in cdx_mmap_resource()
728 * Map memory region and vm->vm_pgoff is expected to be an in cdx_mmap_resource()
731 vma->vm_page_prot = pgprot_device(vma->vm_page_prot); in cdx_mmap_resource()
732 vma->vm_pgoff += (cdx_resource_start(cdx_dev, num) >> PAGE_SHIFT); in cdx_mmap_resource()
733 vma->vm_ops = &cdx_phys_vm_ops; in cdx_mmap_resource()
734 return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, in cdx_mmap_resource()
735 vma->vm_end - vma->vm_start, in cdx_mmap_resource()
736 vma->vm_page_prot); in cdx_mmap_resource()
739 static void cdx_destroy_res_attr(struct cdx_device *cdx_dev, int num) in cdx_destroy_res_attr() argument
744 for (i = 0; i < num; i++) { in cdx_destroy_res_attr()
747 res_attr = cdx_dev->res_attr[i]; in cdx_destroy_res_attr()
749 sysfs_remove_bin_file(&cdx_dev->dev.kobj, res_attr); in cdx_destroy_res_attr()
756 static int cdx_create_res_attr(struct cdx_device *cdx_dev, int num) in cdx_create_res_attr() argument
764 return -ENOMEM; in cdx_create_res_attr()
770 cdx_dev->res_attr[num] = res_attr; in cdx_create_res_attr()
771 sprintf(res_attr_name, "resource%d", num); in cdx_create_res_attr()
773 res_attr->mmap = cdx_mmap_resource; in cdx_create_res_attr()
774 res_attr->attr.name = res_attr_name; in cdx_create_res_attr()
775 res_attr->attr.mode = 0600; in cdx_create_res_attr()
776 res_attr->size = cdx_resource_len(cdx_dev, num); in cdx_create_res_attr()
777 res_attr->private = (void *)(unsigned long)num; in cdx_create_res_attr()
778 ret = sysfs_create_bin_file(&cdx_dev->dev.kobj, res_attr); in cdx_create_res_attr()
787 struct cdx_controller *cdx = dev_params->cdx; in cdx_device_add()
793 return -ENOMEM; in cdx_device_add()
796 memcpy(cdx_dev->res, dev_params->res, sizeof(struct resource) * in cdx_device_add()
797 dev_params->res_count); in cdx_device_add()
798 cdx_dev->res_count = dev_params->res_count; in cdx_device_add()
801 cdx_dev->req_id = dev_params->req_id; in cdx_device_add()
802 cdx_dev->msi_dev_id = dev_params->msi_dev_id; in cdx_device_add()
803 cdx_dev->vendor = dev_params->vendor; in cdx_device_add()
804 cdx_dev->device = dev_params->device; in cdx_device_add()
805 cdx_dev->subsystem_vendor = dev_params->subsys_vendor; in cdx_device_add()
806 cdx_dev->subsystem_device = dev_params->subsys_device; in cdx_device_add()
807 cdx_dev->class = dev_params->class; in cdx_device_add()
808 cdx_dev->revision = dev_params->revision; in cdx_device_add()
809 cdx_dev->bus_num = dev_params->bus_num; in cdx_device_add()
810 cdx_dev->dev_num = dev_params->dev_num; in cdx_device_add()
811 cdx_dev->cdx = dev_params->cdx; in cdx_device_add()
812 cdx_dev->dma_mask = CDX_DEFAULT_DMA_MASK; in cdx_device_add()
815 device_initialize(&cdx_dev->dev); in cdx_device_add()
816 cdx_dev->dev.parent = dev_params->parent; in cdx_device_add()
817 cdx_dev->dev.bus = &cdx_bus_type; in cdx_device_add()
818 cdx_dev->dev.dma_mask = &cdx_dev->dma_mask; in cdx_device_add()
819 cdx_dev->dev.release = cdx_device_release; in cdx_device_add()
820 cdx_dev->msi_write_pending = false; in cdx_device_add()
821 mutex_init(&cdx_dev->irqchip_lock); in cdx_device_add()
824 dev_set_name(&cdx_dev->dev, "cdx-%02x:%02x", in cdx_device_add()
825 ((cdx->id << CDX_CONTROLLER_ID_SHIFT) | (cdx_dev->bus_num & CDX_BUS_NUM_MASK)), in cdx_device_add()
826 cdx_dev->dev_num); in cdx_device_add()
828 if (cdx->msi_domain) { in cdx_device_add()
829 cdx_dev->num_msi = dev_params->num_msi; in cdx_device_add()
830 dev_set_msi_domain(&cdx_dev->dev, cdx->msi_domain); in cdx_device_add()
833 ret = device_add(&cdx_dev->dev); in cdx_device_add()
835 dev_err(&cdx_dev->dev, in cdx_device_add()
849 dev_err(&cdx_dev->dev, in cdx_device_add()
861 device_del(&cdx_dev->dev); in cdx_device_add()
867 put_device(&cdx_dev->dev); in cdx_device_add()
882 device_initialize(&cdx_dev->dev); in cdx_bus_add()
883 cdx_dev->cdx = cdx; in cdx_bus_add()
885 cdx_dev->dev.parent = cdx->dev; in cdx_bus_add()
886 cdx_dev->dev.bus = &cdx_bus_type; in cdx_bus_add()
887 cdx_dev->dev.release = cdx_device_release; in cdx_bus_add()
888 cdx_dev->is_bus = true; in cdx_bus_add()
889 cdx_dev->bus_num = bus_num; in cdx_bus_add()
891 dev_set_name(&cdx_dev->dev, "cdx-%02x", in cdx_bus_add()
892 ((cdx->id << CDX_CONTROLLER_ID_SHIFT) | (bus_num & CDX_BUS_NUM_MASK))); in cdx_bus_add()
894 ret = device_add(&cdx_dev->dev); in cdx_bus_add()
896 dev_err(&cdx_dev->dev, "cdx bus device add failed: %d\n", ret); in cdx_bus_add()
900 if (cdx->ops->bus_enable) { in cdx_bus_add()
901 ret = cdx->ops->bus_enable(cdx, bus_num); in cdx_bus_add()
902 if (ret && ret != -EALREADY) { in cdx_bus_add()
903 dev_err(cdx->dev, "cdx bus enable failed: %d\n", ret); in cdx_bus_add()
908 cdx_dev->enabled = true; in cdx_bus_add()
909 return &cdx_dev->dev; in cdx_bus_add()
912 device_del(&cdx_dev->dev); in cdx_bus_add()
914 put_device(&cdx_dev->dev); in cdx_bus_add()
924 ret = ida_alloc_range(&cdx_controller_ida, 0, MAX_CDX_CONTROLLERS - 1, GFP_KERNEL); in cdx_register_controller()
926 dev_err(cdx->dev, in cdx_register_controller()
928 cdx->id = (u8)MAX_CDX_CONTROLLERS; in cdx_register_controller()
933 cdx->id = ret; in cdx_register_controller()
936 if (cdx->ops->scan) in cdx_register_controller()
937 cdx->ops->scan(cdx); in cdx_register_controller()
938 cdx->controller_registered = true; in cdx_register_controller()
947 if (cdx->id >= MAX_CDX_CONTROLLERS) in cdx_unregister_controller()
952 cdx->controller_registered = false; in cdx_unregister_controller()
953 device_for_each_child(cdx->dev, NULL, cdx_unregister_device); in cdx_unregister_controller()
954 ida_free(&cdx_controller_ida, cdx->id); in cdx_unregister_controller()