Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu/cgs: add an interface to access PCI resources

This provides an interface to get access to the base address
of PCI resources (MMIO, DOORBELL, etc.). Only MMIO and
DOORBELL are implemented right now. This is necessary to
properly utilize shared drivers on platform devices. IP
modules can use this interface to get the base address
of the resource and add any additional offset and set the
size when setting up the platform driver(s).

Acked-by: Dave Airlie <airlied@redhat.com>
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

+70
+36
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
··· 398 398 WARN(ret, "pci_write_config_dword error"); 399 399 } 400 400 401 + 402 + static int amdgpu_cgs_get_pci_resource(void *cgs_device, 403 + enum cgs_resource_type resource_type, 404 + uint64_t size, 405 + uint64_t offset, 406 + uint64_t *resource_base) 407 + { 408 + CGS_FUNC_ADEV; 409 + 410 + if (resource_base == NULL) 411 + return -EINVAL; 412 + 413 + switch (resource_type) { 414 + case CGS_RESOURCE_TYPE_MMIO: 415 + if (adev->rmmio_size == 0) 416 + return -ENOENT; 417 + if ((offset + size) > adev->rmmio_size) 418 + return -EINVAL; 419 + *resource_base = adev->rmmio_base; 420 + return 0; 421 + case CGS_RESOURCE_TYPE_DOORBELL: 422 + if (adev->doorbell.size == 0) 423 + return -ENOENT; 424 + if ((offset + size) > adev->doorbell.size) 425 + return -EINVAL; 426 + *resource_base = adev->doorbell.base; 427 + return 0; 428 + case CGS_RESOURCE_TYPE_FB: 429 + case CGS_RESOURCE_TYPE_IO: 430 + case CGS_RESOURCE_TYPE_ROM: 431 + default: 432 + return -EINVAL; 433 + } 434 + } 435 + 401 436 static const void *amdgpu_cgs_atom_get_data_table(void *cgs_device, 402 437 unsigned table, uint16_t *size, 403 438 uint8_t *frev, uint8_t *crev) ··· 1076 1041 amdgpu_cgs_write_pci_config_byte, 1077 1042 amdgpu_cgs_write_pci_config_word, 1078 1043 amdgpu_cgs_write_pci_config_dword, 1044 + amdgpu_cgs_get_pci_resource, 1079 1045 amdgpu_cgs_atom_get_data_table, 1080 1046 amdgpu_cgs_atom_get_cmd_table_revs, 1081 1047 amdgpu_cgs_atom_exec_cmd_table,
+34
drivers/gpu/drm/amd/include/cgs_common.h
··· 122 122 uint64_t padding[13]; 123 123 }; 124 124 125 + /* 126 + * enum cgs_resource_type - GPU resource type 127 + */ 128 + enum cgs_resource_type { 129 + CGS_RESOURCE_TYPE_MMIO = 0, 130 + CGS_RESOURCE_TYPE_FB, 131 + CGS_RESOURCE_TYPE_IO, 132 + CGS_RESOURCE_TYPE_DOORBELL, 133 + CGS_RESOURCE_TYPE_ROM, 134 + }; 135 + 125 136 /** 126 137 * struct cgs_clock_limits - Clock limits 127 138 * ··· 428 417 typedef void (*cgs_write_pci_config_dword_t)(void *cgs_device, unsigned addr, 429 418 uint32_t value); 430 419 420 + 421 + /** 422 + * cgs_get_pci_resource() - provide access to a device resource (PCI BAR) 423 + * @cgs_device: opaque device handle 424 + * @resource_type: Type of Resource (MMIO, IO, ROM, FB, DOORBELL) 425 + * @size: size of the region 426 + * @offset: offset from the start of the region 427 + * @resource_base: base address (not including offset) returned 428 + * 429 + * Return: 0 on success, -errno otherwise 430 + */ 431 + typedef int (*cgs_get_pci_resource_t)(void *cgs_device, 432 + enum cgs_resource_type resource_type, 433 + uint64_t size, 434 + uint64_t offset, 435 + uint64_t *resource_base); 436 + 431 437 /** 432 438 * cgs_atom_get_data_table() - Get a pointer to an ATOM BIOS data table 433 439 * @cgs_device: opaque device handle ··· 621 593 cgs_write_pci_config_byte_t write_pci_config_byte; 622 594 cgs_write_pci_config_word_t write_pci_config_word; 623 595 cgs_write_pci_config_dword_t write_pci_config_dword; 596 + /* PCI resources */ 597 + cgs_get_pci_resource_t get_pci_resource; 624 598 /* ATOM BIOS */ 625 599 cgs_atom_get_data_table_t atom_get_data_table; 626 600 cgs_atom_get_cmd_table_revs_t atom_get_cmd_table_revs; ··· 738 708 CGS_CALL(call_acpi_method, dev, acpi_method, acpi_function, pintput, poutput, output_count, input_size, output_size) 739 709 #define cgs_query_system_info(dev, sys_info) \ 740 710 CGS_CALL(query_system_info, dev, sys_info) 711 + #define cgs_get_pci_resource(cgs_device, resource_type, size, offset, \ 712 + resource_base) \ 713 + CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \ 714 + resource_base) 741 715 742 716 #endif /* _CGS_COMMON_H */