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

PCI: Remove hybrid devres nature from request functions

All functions based on __pci_request_region() and its release counter
part support "hybrid mode", where the functions become managed if the
PCI device was enabled with pcim_enable_device().

Removing this undesirable feature requires to remove all users who
activated their device with that function and use one of the affected
request functions.

These users were:
ASoC
alsa
cardreader
cirrus
i2c
mmc
mtd
mtd
mxser
net
spi
vdpa
vmwgfx

all of which have been ported to always-managed pcim_ functions by now.

The hybrid nature can, thus, be removed from the aforementioned PCI
functions.

Remove all function guards and documentation in pci.c related to the
hybrid redirection. Adjust the visibility of pcim_release_region().

Signed-off-by: Philipp Stanner <phasta@kernel.org>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Link: https://lore.kernel.org/r/20250519112959.25487-3-phasta@kernel.org

authored by

Philipp Stanner and committed by
Krzysztof Wilczyński
51f6aec9 855c6349

+12 -70
+12 -27
drivers/pci/devres.c
··· 6 6 /* 7 7 * On the state of PCI's devres implementation: 8 8 * 9 - * The older devres API for PCI has two significant problems: 9 + * The older PCI devres API has one significant problem: 10 10 * 11 - * 1. It is very strongly tied to the statically allocated mapping table in 12 - * struct pcim_iomap_devres below. This is mostly solved in the sense of the 13 - * pcim_ functions in this file providing things like ranged mapping by 14 - * bypassing this table, whereas the functions that were present in the old 15 - * API still enter the mapping addresses into the table for users of the old 16 - * API. 17 - * 18 - * 2. The region-request-functions in pci.c do become managed IF the device has 19 - * been enabled with pcim_enable_device() instead of pci_enable_device(). 20 - * This resulted in the API becoming inconsistent: Some functions have an 21 - * obviously managed counter-part (e.g., pci_iomap() <-> pcim_iomap()), 22 - * whereas some don't and are never managed, while others don't and are 23 - * _sometimes_ managed (e.g. pci_request_region()). 24 - * 25 - * Consequently, in the new API, region requests performed by the pcim_ 26 - * functions are automatically cleaned up through the devres callback 27 - * pcim_addr_resource_release(). 28 - * 29 - * Users of pcim_enable_device() + pci_*region*() are redirected in 30 - * pci.c to the managed functions here in this file. This isn't exactly 31 - * perfect, but the only alternative way would be to port ALL drivers 32 - * using said combination to pcim_ functions. 11 + * It is very strongly tied to the statically allocated mapping table in struct 12 + * pcim_iomap_devres below. This is mostly solved in the sense of the pcim_ 13 + * functions in this file providing things like ranged mapping by bypassing 14 + * this table, whereas the functions that were present in the old API still 15 + * enter the mapping addresses into the table for users of the old API. 33 16 * 34 17 * TODO: 35 18 * Remove the legacy table entirely once all calls to pcim_iomap_table() in ··· 72 89 73 90 /* 74 91 * The following functions, __pcim_*_region*, exist as counterparts to the 75 - * versions from pci.c - which, unfortunately, can be in "hybrid mode", i.e., 76 - * sometimes managed, sometimes not. 92 + * versions from pci.c - which, unfortunately, were in the past in "hybrid 93 + * mode", i.e., sometimes managed, sometimes not. 77 94 * 78 - * To separate the APIs cleanly, we define our own, simplified versions here. 95 + * To separate the APIs cleanly, we defined our own, simplified versions here. 96 + * 97 + * TODO: unify those functions with the counterparts in pci.c 79 98 */ 80 99 81 100 /** ··· 878 893 * Release a region manually that was previously requested by 879 894 * pcim_request_region(). 880 895 */ 881 - void pcim_release_region(struct pci_dev *pdev, int bar) 896 + static void pcim_release_region(struct pci_dev *pdev, int bar) 882 897 { 883 898 struct pcim_addr_devres res_searched; 884 899
-42
drivers/pci/pci.c
··· 3937 3937 if (!pci_bar_index_is_valid(bar)) 3938 3938 return; 3939 3939 3940 - /* 3941 - * This is done for backwards compatibility, because the old PCI devres 3942 - * API had a mode in which the function became managed if it had been 3943 - * enabled with pcim_enable_device() instead of pci_enable_device(). 3944 - */ 3945 - if (pci_is_managed(pdev)) { 3946 - pcim_release_region(pdev, bar); 3947 - return; 3948 - } 3949 - 3950 3940 if (pci_resource_len(pdev, bar) == 0) 3951 3941 return; 3952 3942 if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) ··· 3974 3984 if (!pci_bar_index_is_valid(bar)) 3975 3985 return -EINVAL; 3976 3986 3977 - if (pci_is_managed(pdev)) { 3978 - if (exclusive == IORESOURCE_EXCLUSIVE) 3979 - return pcim_request_region_exclusive(pdev, bar, name); 3980 - 3981 - return pcim_request_region(pdev, bar, name); 3982 - } 3983 - 3984 3987 if (pci_resource_len(pdev, bar) == 0) 3985 3988 return 0; 3986 3989 ··· 4010 4027 * 4011 4028 * Returns 0 on success, or %EBUSY on error. A warning 4012 4029 * message is also printed on failure. 4013 - * 4014 - * NOTE: 4015 - * This is a "hybrid" function: It's normally unmanaged, but becomes managed 4016 - * when pcim_enable_device() has been called in advance. This hybrid feature is 4017 - * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. 4018 4030 */ 4019 4031 int pci_request_region(struct pci_dev *pdev, int bar, const char *name) 4020 4032 { ··· 4062 4084 * @name: Name of the driver requesting the resources 4063 4085 * 4064 4086 * Returns: 0 on success, negative error code on failure. 4065 - * 4066 - * NOTE: 4067 - * This is a "hybrid" function: It's normally unmanaged, but becomes managed 4068 - * when pcim_enable_device() has been called in advance. This hybrid feature is 4069 - * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. 4070 4087 */ 4071 4088 int pci_request_selected_regions(struct pci_dev *pdev, int bars, 4072 4089 const char *name) ··· 4077 4104 * @name: name of the driver requesting the resources 4078 4105 * 4079 4106 * Returns: 0 on success, negative error code on failure. 4080 - * 4081 - * NOTE: 4082 - * This is a "hybrid" function: It's normally unmanaged, but becomes managed 4083 - * when pcim_enable_device() has been called in advance. This hybrid feature is 4084 - * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. 4085 4107 */ 4086 4108 int pci_request_selected_regions_exclusive(struct pci_dev *pdev, int bars, 4087 4109 const char *name) ··· 4112 4144 * 4113 4145 * Returns 0 on success, or %EBUSY on error. A warning 4114 4146 * message is also printed on failure. 4115 - * 4116 - * NOTE: 4117 - * This is a "hybrid" function: It's normally unmanaged, but becomes managed 4118 - * when pcim_enable_device() has been called in advance. This hybrid feature is 4119 - * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. 4120 4147 */ 4121 4148 int pci_request_regions(struct pci_dev *pdev, const char *name) 4122 4149 { ··· 4136 4173 * 4137 4174 * Returns 0 on success, or %EBUSY on error. A warning message is also 4138 4175 * printed on failure. 4139 - * 4140 - * NOTE: 4141 - * This is a "hybrid" function: It's normally unmanaged, but becomes managed 4142 - * when pcim_enable_device() has been called in advance. This hybrid feature is 4143 - * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. 4144 4176 */ 4145 4177 int pci_request_regions_exclusive(struct pci_dev *pdev, const char *name) 4146 4178 {
-1
drivers/pci/pci.h
··· 1062 1062 int pcim_intx(struct pci_dev *dev, int enable); 1063 1063 int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, 1064 1064 const char *name); 1065 - void pcim_release_region(struct pci_dev *pdev, int bar); 1066 1065 1067 1066 /* 1068 1067 * Config Address for PCI Configuration Mechanism #1