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
70 #include <linux/dma-map-ops.h>
85 static char *compat_node_name = "xlnx,versal-net-cdx";
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
216 while (ids->vendor || ids->device) { 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
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()
290 if (!found_id->override_only) in cdx_bus_match()
292 if (cdx_dev->driver_override) 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()
341 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_shutdown()
343 if (cdx_dev->is_bus && cdx_dev->enabled && cdx->ops->bus_disable) in cdx_shutdown()
344 cdx->ops->bus_disable(cdx, cdx_dev->bus_num); in cdx_shutdown()
345 if (cdx_drv && cdx_drv->shutdown) in cdx_shutdown()
346 cdx_drv->shutdown(cdx_dev); in cdx_shutdown()
351 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_dma_configure()
353 struct cdx_controller *cdx = cdx_dev->cdx; in cdx_dma_configure()
354 u32 input_id = cdx_dev->req_id; in cdx_dma_configure()
357 ret = of_dma_configure_id(dev, cdx->dev->of_node, 0, &input_id); in cdx_dma_configure()
358 if (ret && ret != -EPROBE_DEFER) { in cdx_dma_configure()
363 if (!ret && !cdx_drv->driver_managed_dma) { in cdx_dma_configure()
374 struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver); in cdx_dma_cleanup()
376 if (!cdx_drv->driver_managed_dma) in cdx_dma_cleanup()
386 return sysfs_emit(buf, format_string, cdx_dev->field); \
404 return -EINVAL; in remove_store()
407 return -EINVAL; in remove_store()
429 return -EINVAL; in reset_store()
432 return -EINVAL; in reset_store()
434 if (cdx_dev->is_bus) in reset_store()
449 return sprintf(buf, "cdx:v%04Xd%04Xsv%04Xsd%04Xc%06X\n", cdx_dev->vendor, in modalias_show()
450 cdx_dev->device, cdx_dev->subsystem_vendor, cdx_dev->subsystem_device, in modalias_show()
451 cdx_dev->class); in modalias_show()
462 if (WARN_ON(dev->bus != &cdx_bus_type)) in driver_override_store()
463 return -EINVAL; in driver_override_store()
465 ret = driver_set_override(dev, &cdx_dev->driver_override, buf, count); in driver_override_store()
479 len = sysfs_emit(buf, "%s\n", cdx_dev->driver_override); in driver_override_show()
489 struct cdx_controller *cdx = cdx_dev->cdx; in enable_store()
494 return -EINVAL; in enable_store()
496 if (enable == cdx_dev->enabled) in enable_store()
499 if (enable && cdx->ops->bus_enable) in enable_store()
500 ret = cdx->ops->bus_enable(cdx, cdx_dev->bus_num); in enable_store()
501 else if (!enable && cdx->ops->bus_disable) in enable_store()
502 ret = cdx->ops->bus_disable(cdx, cdx_dev->bus_num); in enable_store()
504 ret = -EOPNOTSUPP; in enable_store()
507 cdx_dev->enabled = enable; in enable_store()
516 return sysfs_emit(buf, "%u\n", cdx_dev->enabled); in enable_show()
526 if (!cdx_dev->is_bus) in cdx_dev_attrs_are_visible()
527 return a->mode; in cdx_dev_attrs_are_visible()
538 if (cdx_dev->is_bus) in cdx_bus_attrs_are_visible()
539 return a->mode; in cdx_bus_attrs_are_visible()
582 struct cdx_device *cdx_dev = s->private; in cdx_debug_resource_show()
586 struct resource *res = &cdx_dev->res[i]; in cdx_debug_resource_show()
597 cdx_dev->debugfs_dir = debugfs_create_dir(dev_name(&cdx_dev->dev), cdx_debugfs_dir); in cdx_device_debugfs_init()
598 if (IS_ERR(cdx_dev->debugfs_dir)) in cdx_device_debugfs_init()
601 debugfs_create_file("resource", 0444, cdx_dev->debugfs_dir, cdx_dev, in cdx_device_debugfs_init()
614 return -EINVAL; in rescan_store()
617 return -EINVAL; in rescan_store()
629 count = -EINVAL; in rescan_store()
634 if (cdx && cdx->controller_registered && cdx->ops->scan) in rescan_store()
635 cdx->ops->scan(cdx); in rescan_store()
637 put_device(&pd->dev); in rescan_store()
671 cdx_driver->driver.owner = owner; in __cdx_driver_register()
672 cdx_driver->driver.bus = &cdx_bus_type; in __cdx_driver_register()
674 error = driver_register(&cdx_driver->driver); in __cdx_driver_register()
677 cdx_driver->driver.name, error); in __cdx_driver_register()
687 driver_unregister(&cdx_driver->driver); in cdx_driver_unregister()
705 * cdx_mmap_resource - map a CDX resource into user memory space
721 int num = (unsigned long)attr->private; in cdx_mmap_resource()
725 res = &cdx_dev->res[num]; in cdx_mmap_resource()
726 if (iomem_is_exclusive(res->start)) in cdx_mmap_resource()
727 return -EINVAL; in cdx_mmap_resource()
730 size = ((cdx_resource_len(cdx_dev, num) - 1) >> PAGE_SHIFT) + 1; in cdx_mmap_resource()
731 if (vma->vm_pgoff + vma_pages(vma) > size) in cdx_mmap_resource()
732 return -EINVAL; in cdx_mmap_resource()
735 * Map memory region and vm->vm_pgoff is expected to be an in cdx_mmap_resource()
738 vma->vm_page_prot = pgprot_device(vma->vm_page_prot); in cdx_mmap_resource()
739 vma->vm_pgoff += (cdx_resource_start(cdx_dev, num) >> PAGE_SHIFT); in cdx_mmap_resource()
740 vma->vm_ops = &cdx_phys_vm_ops; in cdx_mmap_resource()
741 return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, in cdx_mmap_resource()
742 vma->vm_end - vma->vm_start, in cdx_mmap_resource()
743 vma->vm_page_prot); in cdx_mmap_resource()
754 res_attr = cdx_dev->res_attr[i]; in cdx_destroy_res_attr()
756 sysfs_remove_bin_file(&cdx_dev->dev.kobj, res_attr); in cdx_destroy_res_attr()
771 return -ENOMEM; in cdx_create_res_attr()
777 cdx_dev->res_attr[num] = res_attr; in cdx_create_res_attr()
780 res_attr->mmap = cdx_mmap_resource; in cdx_create_res_attr()
781 res_attr->attr.name = res_attr_name; in cdx_create_res_attr()
782 res_attr->attr.mode = 0600; in cdx_create_res_attr()
783 res_attr->size = cdx_resource_len(cdx_dev, num); in cdx_create_res_attr()
784 res_attr->private = (void *)(unsigned long)num; in cdx_create_res_attr()
785 ret = sysfs_create_bin_file(&cdx_dev->dev.kobj, res_attr); in cdx_create_res_attr()
794 struct cdx_controller *cdx = dev_params->cdx; in cdx_device_add()
800 return -ENOMEM; in cdx_device_add()
803 memcpy(cdx_dev->res, dev_params->res, sizeof(struct resource) * in cdx_device_add()
804 dev_params->res_count); in cdx_device_add()
805 cdx_dev->res_count = dev_params->res_count; in cdx_device_add()
808 cdx_dev->req_id = dev_params->req_id; in cdx_device_add()
809 cdx_dev->msi_dev_id = dev_params->msi_dev_id; in cdx_device_add()
810 cdx_dev->vendor = dev_params->vendor; in cdx_device_add()
811 cdx_dev->device = dev_params->device; in cdx_device_add()
812 cdx_dev->subsystem_vendor = dev_params->subsys_vendor; in cdx_device_add()
813 cdx_dev->subsystem_device = dev_params->subsys_device; in cdx_device_add()
814 cdx_dev->class = dev_params->class; in cdx_device_add()
815 cdx_dev->revision = dev_params->revision; in cdx_device_add()
816 cdx_dev->bus_num = dev_params->bus_num; in cdx_device_add()
817 cdx_dev->dev_num = dev_params->dev_num; in cdx_device_add()
818 cdx_dev->cdx = dev_params->cdx; in cdx_device_add()
819 cdx_dev->dma_mask = CDX_DEFAULT_DMA_MASK; in cdx_device_add()
822 device_initialize(&cdx_dev->dev); in cdx_device_add()
823 cdx_dev->dev.parent = dev_params->parent; in cdx_device_add()
824 cdx_dev->dev.bus = &cdx_bus_type; in cdx_device_add()
825 cdx_dev->dev.dma_mask = &cdx_dev->dma_mask; in cdx_device_add()
826 cdx_dev->dev.release = cdx_device_release; in cdx_device_add()
827 cdx_dev->msi_write_pending = false; in cdx_device_add()
828 mutex_init(&cdx_dev->irqchip_lock); in cdx_device_add()
831 dev_set_name(&cdx_dev->dev, "cdx-%02x:%02x", in cdx_device_add()
832 ((cdx->id << CDX_CONTROLLER_ID_SHIFT) | (cdx_dev->bus_num & CDX_BUS_NUM_MASK)), in cdx_device_add()
833 cdx_dev->dev_num); in cdx_device_add()
835 if (cdx->msi_domain) { in cdx_device_add()
836 cdx_dev->num_msi = dev_params->num_msi; in cdx_device_add()
837 dev_set_msi_domain(&cdx_dev->dev, cdx->msi_domain); in cdx_device_add()
840 ret = device_add(&cdx_dev->dev); in cdx_device_add()
842 dev_err(&cdx_dev->dev, in cdx_device_add()
856 dev_err(&cdx_dev->dev, in cdx_device_add()
868 device_del(&cdx_dev->dev); in cdx_device_add()
874 put_device(&cdx_dev->dev); in cdx_device_add()
889 device_initialize(&cdx_dev->dev); in cdx_bus_add()
890 cdx_dev->cdx = cdx; in cdx_bus_add()
892 cdx_dev->dev.parent = cdx->dev; in cdx_bus_add()
893 cdx_dev->dev.bus = &cdx_bus_type; in cdx_bus_add()
894 cdx_dev->dev.release = cdx_device_release; in cdx_bus_add()
895 cdx_dev->is_bus = true; in cdx_bus_add()
896 cdx_dev->bus_num = bus_num; in cdx_bus_add()
898 dev_set_name(&cdx_dev->dev, "cdx-%02x", in cdx_bus_add()
899 ((cdx->id << CDX_CONTROLLER_ID_SHIFT) | (bus_num & CDX_BUS_NUM_MASK))); in cdx_bus_add()
901 ret = device_add(&cdx_dev->dev); in cdx_bus_add()
903 dev_err(&cdx_dev->dev, "cdx bus device add failed: %d\n", ret); in cdx_bus_add()
907 if (cdx->ops->bus_enable) { in cdx_bus_add()
908 ret = cdx->ops->bus_enable(cdx, bus_num); in cdx_bus_add()
909 if (ret && ret != -EALREADY) { in cdx_bus_add()
910 dev_err(cdx->dev, "cdx bus enable failed: %d\n", ret); in cdx_bus_add()
915 cdx_dev->enabled = true; in cdx_bus_add()
916 return &cdx_dev->dev; in cdx_bus_add()
919 device_del(&cdx_dev->dev); in cdx_bus_add()
921 put_device(&cdx_dev->dev); in cdx_bus_add()
931 ret = ida_alloc_range(&cdx_controller_ida, 0, MAX_CDX_CONTROLLERS - 1, GFP_KERNEL); in cdx_register_controller()
933 dev_err(cdx->dev, in cdx_register_controller()
935 cdx->id = (u8)MAX_CDX_CONTROLLERS; in cdx_register_controller()
940 cdx->id = ret; in cdx_register_controller()
943 if (cdx->ops->scan) in cdx_register_controller()
944 cdx->ops->scan(cdx); in cdx_register_controller()
945 cdx->controller_registered = true; in cdx_register_controller()
954 if (cdx->id >= MAX_CDX_CONTROLLERS) in cdx_unregister_controller()
959 cdx->controller_registered = false; in cdx_unregister_controller()
960 device_for_each_child(cdx->dev, NULL, cdx_unregister_device); in cdx_unregister_controller()
961 ida_free(&cdx_controller_ida, cdx->id); in cdx_unregister_controller()