Lines Matching +full:versal +full:- +full:fpga

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
11 * CDX is a Hardware Architecture designed for AMD FPGA devices. It
12 * consists of sophisticated mechanism for interaction between FPGA,
16 * the FPGA program manager and the APUs. The RPU provides memory-mapped
21 * +--------------------------------------+
30 * +-----------------------------|--------+
34 * +------------------------| RPU if |----+
39 * +--------------------------------------+
41 * +---------------------|----------------+
42 * | FPGA | |
43 * | +-----------------------+ |
45 * | +-------+ +-------+ +-------+ |
47 * | +-------+ +-------+ +-------+ |
48 * +--------------------------------------+
50 * The RPU firmware extracts the device information from the loaded FPGA
54 * discover, reset and rescan of the FPGA devices for the APU. This is
69 #include <linux/dma-map-ops.h>
84 static char *compat_node_name = "xlnx,versal-net-cdx";
89 * cdx_dev_reset - Reset a CDX device
92 * Return: -errno on failure, 0 on success.
97 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_dev_reset()
102 cdx_drv = to_cdx_driver(dev->driver); in cdx_dev_reset()
104 if (cdx_drv && cdx_drv->reset_prepare) in cdx_dev_reset()
105 cdx_drv->reset_prepare(cdx_dev); in cdx_dev_reset()
108 ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num, in cdx_dev_reset()
109 cdx_dev->dev_num, &dev_config); in cdx_dev_reset()
114 if (cdx_drv && cdx_drv->reset_done) in cdx_dev_reset()
115 cdx_drv->reset_done(cdx_dev); in cdx_dev_reset()
122 * reset_cdx_device - Reset a CDX device
128 * Return: -errno on failure, 0 on success.
136 * cdx_unregister_device - Unregister a CDX device
149 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_unregister_device()
151 if (cdx_dev->is_bus) { in cdx_unregister_device()
153 if (cdx_dev->enabled && cdx->ops->bus_disable) in cdx_unregister_device()
154 cdx->ops->bus_disable(cdx, cdx_dev->bus_num); in cdx_unregister_device()
157 debugfs_remove_recursive(cdx_dev->debugfs_dir); in cdx_unregister_device()
158 kfree(cdx_dev->driver_override); in cdx_unregister_device()
159 cdx_dev->driver_override = NULL; in cdx_unregister_device()
166 device_del(&cdx_dev->dev); in cdx_unregister_device()
167 put_device(&cdx_dev->dev); in cdx_unregister_device()
179 * cdx_match_one_device - Tell if a CDX device structure has a matching
191 if ((id->vendor == CDX_ANY_ID || id->vendor == dev->vendor) && in cdx_match_one_device()
192 (id->device == CDX_ANY_ID || id->device == dev->device) && in cdx_match_one_device()
193 (id->subvendor == CDX_ANY_ID || id->subvendor == dev->subsystem_vendor) && in cdx_match_one_device()
194 (id->subdevice == CDX_ANY_ID || id->subdevice == dev->subsystem_device) && in cdx_match_one_device()
195 !((id->class ^ dev->class) & id->class_mask)) in cdx_match_one_device()
201 * cdx_match_id - See if a CDX device matches a given cdx_id table
215 while (ids->vendor || ids->device) { in cdx_match_id()
226 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_set_master()
228 int ret = -EOPNOTSUPP; in cdx_set_master()
232 if (cdx->ops->dev_configure) in cdx_set_master()
233 ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num, in cdx_set_master()
234 cdx_dev->dev_num, &dev_config); in cdx_set_master()
242 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_clear_master()
244 int ret = -EOPNOTSUPP; in cdx_clear_master()
248 if (cdx->ops->dev_configure) in cdx_clear_master()
249 ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num, in cdx_clear_master()
250 cdx_dev->dev_num, &dev_config); in cdx_clear_master()
257 * cdx_bus_match - device to driver matching callback
271 if (cdx_dev->is_bus) in cdx_bus_match()
274 ids = cdx_drv->match_id_table; in cdx_bus_match()
277 if (cdx_dev->driver_override && strcmp(cdx_dev->driver_override, drv->name)) in cdx_bus_match()
289 if (!found_id->override_only) in cdx_bus_match()
291 if (cdx_dev->driver_override) in cdx_bus_match()
303 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_probe()
307 error = cdx_drv->probe(cdx_dev); in cdx_probe()
318 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_remove()
321 if (cdx_drv && cdx_drv->remove) in cdx_remove()
322 cdx_drv->remove(cdx_dev); in cdx_remove()
327 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_shutdown()
330 if (cdx_drv && cdx_drv->shutdown) in cdx_shutdown()
331 cdx_drv->shutdown(cdx_dev); in cdx_shutdown()
336 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_dma_configure()
338 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_dma_configure()
339 u32 input_id = cdx_dev->req_id; in cdx_dma_configure()
342 ret = of_dma_configure_id(dev, cdx->dev->of_node, 0, &input_id); in cdx_dma_configure()
343 if (ret && ret != -EPROBE_DEFER) { in cdx_dma_configure()
348 if (!ret && !cdx_drv->driver_managed_dma) { in cdx_dma_configure()
359 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_dma_cleanup()
361 if (!cdx_drv->driver_managed_dma) in cdx_dma_cleanup()
371 return sysfs_emit(buf, format_string, cdx_dev->field); \
389 return -EINVAL; in remove_store()
392 return -EINVAL; in remove_store()
414 return -EINVAL; in reset_store()
417 return -EINVAL; in reset_store()
419 if (cdx_dev->is_bus) in reset_store()
434 return sprintf(buf, "cdx:v%04Xd%04Xsv%04Xsd%04Xc%06X\n", cdx_dev->vendor, in modalias_show()
435 cdx_dev->device, cdx_dev->subsystem_vendor, cdx_dev->subsystem_device, in modalias_show()
436 cdx_dev->class); in modalias_show()
447 if (WARN_ON(dev->bus != &cdx_bus_type)) in driver_override_store()
448 return -EINVAL; in driver_override_store()
450 ret = driver_set_override(dev, &cdx_dev->driver_override, buf, count); in driver_override_store()
462 return sysfs_emit(buf, "%s\n", cdx_dev->driver_override); in driver_override_show()
470 struct cdx_controller *cdx = cdx_dev->cdx; in enable_store()
475 return -EINVAL; in enable_store()
477 if (enable == cdx_dev->enabled) in enable_store()
480 if (enable && cdx->ops->bus_enable) in enable_store()
481 ret = cdx->ops->bus_enable(cdx, cdx_dev->bus_num); in enable_store()
482 else if (!enable && cdx->ops->bus_disable) in enable_store()
483 ret = cdx->ops->bus_disable(cdx, cdx_dev->bus_num); in enable_store()
485 ret = -EOPNOTSUPP; in enable_store()
488 cdx_dev->enabled = enable; in enable_store()
497 return sysfs_emit(buf, "%u\n", cdx_dev->enabled); in enable_show()
507 if (!cdx_dev->is_bus) in cdx_dev_attrs_are_visible()
508 return a->mode; in cdx_dev_attrs_are_visible()
519 if (cdx_dev->is_bus) in cdx_bus_attrs_are_visible()
520 return a->mode; in cdx_bus_attrs_are_visible()
563 struct cdx_device *cdx_dev = s->private; in cdx_debug_resource_show()
567 struct resource *res = &cdx_dev->res[i]; in cdx_debug_resource_show()
578 cdx_dev->debugfs_dir = debugfs_create_dir(dev_name(&cdx_dev->dev), cdx_debugfs_dir); in cdx_device_debugfs_init()
579 if (IS_ERR(cdx_dev->debugfs_dir)) in cdx_device_debugfs_init()
582 debugfs_create_file("resource", 0444, cdx_dev->debugfs_dir, cdx_dev, in cdx_device_debugfs_init()
595 return -EINVAL; in rescan_store()
598 return -EINVAL; in rescan_store()
610 count = -EINVAL; in rescan_store()
615 if (cdx && cdx->controller_registered && cdx->ops->scan) in rescan_store()
616 cdx->ops->scan(cdx); in rescan_store()
618 put_device(&pd->dev); in rescan_store()
652 cdx_driver->driver.owner = owner; in __cdx_driver_register()
653 cdx_driver->driver.bus = &cdx_bus_type; in __cdx_driver_register()
655 error = driver_register(&cdx_driver->driver); in __cdx_driver_register()
658 cdx_driver->driver.name, error); in __cdx_driver_register()
668 driver_unregister(&cdx_driver->driver); in cdx_driver_unregister()
686 * cdx_mmap_resource - map a CDX resource into user memory space
702 int num = (unsigned long)attr->private; in cdx_mmap_resource()
706 res = &cdx_dev->res[num]; in cdx_mmap_resource()
707 if (iomem_is_exclusive(res->start)) in cdx_mmap_resource()
708 return -EINVAL; in cdx_mmap_resource()
711 size = ((cdx_resource_len(cdx_dev, num) - 1) >> PAGE_SHIFT) + 1; in cdx_mmap_resource()
712 if (vma->vm_pgoff + vma_pages(vma) > size) in cdx_mmap_resource()
713 return -EINVAL; in cdx_mmap_resource()
716 * Map memory region and vm->vm_pgoff is expected to be an in cdx_mmap_resource()
719 vma->vm_page_prot = pgprot_device(vma->vm_page_prot); in cdx_mmap_resource()
720 vma->vm_pgoff += (cdx_resource_start(cdx_dev, num) >> PAGE_SHIFT); in cdx_mmap_resource()
721 vma->vm_ops = &cdx_phys_vm_ops; in cdx_mmap_resource()
722 return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, in cdx_mmap_resource()
723 vma->vm_end - vma->vm_start, in cdx_mmap_resource()
724 vma->vm_page_prot); in cdx_mmap_resource()
735 res_attr = cdx_dev->res_attr[i]; in cdx_destroy_res_attr()
737 sysfs_remove_bin_file(&cdx_dev->dev.kobj, res_attr); in cdx_destroy_res_attr()
752 return -ENOMEM; in cdx_create_res_attr()
758 cdx_dev->res_attr[num] = res_attr; in cdx_create_res_attr()
761 res_attr->mmap = cdx_mmap_resource; in cdx_create_res_attr()
762 res_attr->attr.name = res_attr_name; in cdx_create_res_attr()
763 res_attr->attr.mode = 0600; in cdx_create_res_attr()
764 res_attr->size = cdx_resource_len(cdx_dev, num); in cdx_create_res_attr()
765 res_attr->private = (void *)(unsigned long)num; in cdx_create_res_attr()
766 ret = sysfs_create_bin_file(&cdx_dev->dev.kobj, res_attr); in cdx_create_res_attr()
775 struct cdx_controller *cdx = dev_params->cdx; in cdx_device_add()
781 return -ENOMEM; in cdx_device_add()
784 memcpy(cdx_dev->res, dev_params->res, sizeof(struct resource) * in cdx_device_add()
785 dev_params->res_count); in cdx_device_add()
786 cdx_dev->res_count = dev_params->res_count; in cdx_device_add()
789 cdx_dev->req_id = dev_params->req_id; in cdx_device_add()
790 cdx_dev->vendor = dev_params->vendor; in cdx_device_add()
791 cdx_dev->device = dev_params->device; in cdx_device_add()
792 cdx_dev->subsystem_vendor = dev_params->subsys_vendor; in cdx_device_add()
793 cdx_dev->subsystem_device = dev_params->subsys_device; in cdx_device_add()
794 cdx_dev->class = dev_params->class; in cdx_device_add()
795 cdx_dev->revision = dev_params->revision; in cdx_device_add()
796 cdx_dev->bus_num = dev_params->bus_num; in cdx_device_add()
797 cdx_dev->dev_num = dev_params->dev_num; in cdx_device_add()
798 cdx_dev->cdx = dev_params->cdx; in cdx_device_add()
799 cdx_dev->dma_mask = CDX_DEFAULT_DMA_MASK; in cdx_device_add()
802 device_initialize(&cdx_dev->dev); in cdx_device_add()
803 cdx_dev->dev.parent = dev_params->parent; in cdx_device_add()
804 cdx_dev->dev.bus = &cdx_bus_type; in cdx_device_add()
805 cdx_dev->dev.dma_mask = &cdx_dev->dma_mask; in cdx_device_add()
806 cdx_dev->dev.release = cdx_device_release; in cdx_device_add()
809 dev_set_name(&cdx_dev->dev, "cdx-%02x:%02x", in cdx_device_add()
810 ((cdx->id << CDX_CONTROLLER_ID_SHIFT) | (cdx_dev->bus_num & CDX_BUS_NUM_MASK)), in cdx_device_add()
811 cdx_dev->dev_num); in cdx_device_add()
813 ret = device_add(&cdx_dev->dev); in cdx_device_add()
815 dev_err(&cdx_dev->dev, in cdx_device_add()
829 dev_err(&cdx_dev->dev, in cdx_device_add()
841 device_del(&cdx_dev->dev); in cdx_device_add()
847 put_device(&cdx_dev->dev); in cdx_device_add()
862 device_initialize(&cdx_dev->dev); in cdx_bus_add()
863 cdx_dev->cdx = cdx; in cdx_bus_add()
865 cdx_dev->dev.parent = cdx->dev; in cdx_bus_add()
866 cdx_dev->dev.bus = &cdx_bus_type; in cdx_bus_add()
867 cdx_dev->dev.release = cdx_device_release; in cdx_bus_add()
868 cdx_dev->is_bus = true; in cdx_bus_add()
869 cdx_dev->bus_num = bus_num; in cdx_bus_add()
871 dev_set_name(&cdx_dev->dev, "cdx-%02x", in cdx_bus_add()
872 ((cdx->id << CDX_CONTROLLER_ID_SHIFT) | (bus_num & CDX_BUS_NUM_MASK))); in cdx_bus_add()
874 ret = device_add(&cdx_dev->dev); in cdx_bus_add()
876 dev_err(&cdx_dev->dev, "cdx bus device add failed: %d\n", ret); in cdx_bus_add()
880 if (cdx->ops->bus_enable) { in cdx_bus_add()
881 ret = cdx->ops->bus_enable(cdx, bus_num); in cdx_bus_add()
882 if (ret && ret != -EALREADY) { in cdx_bus_add()
883 dev_err(cdx->dev, "cdx bus enable failed: %d\n", ret); in cdx_bus_add()
888 cdx_dev->enabled = true; in cdx_bus_add()
889 return &cdx_dev->dev; in cdx_bus_add()
892 device_del(&cdx_dev->dev); in cdx_bus_add()
894 put_device(&cdx_dev->dev); in cdx_bus_add()
904 ret = ida_alloc_range(&cdx_controller_ida, 0, MAX_CDX_CONTROLLERS - 1, GFP_KERNEL); in cdx_register_controller()
906 dev_err(cdx->dev, in cdx_register_controller()
908 cdx->id = (u8)MAX_CDX_CONTROLLERS; in cdx_register_controller()
913 cdx->id = ret; in cdx_register_controller()
916 if (cdx->ops->scan) in cdx_register_controller()
917 cdx->ops->scan(cdx); in cdx_register_controller()
918 cdx->controller_registered = true; in cdx_register_controller()
927 if (cdx->id >= MAX_CDX_CONTROLLERS) in cdx_unregister_controller()
932 cdx->controller_registered = false; in cdx_unregister_controller()
933 device_for_each_child(cdx->dev, NULL, cdx_unregister_device); in cdx_unregister_controller()
934 ida_free(&cdx_controller_ida, cdx->id); in cdx_unregister_controller()