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

Configure Feed

Select the types of activity you want to include in your feed.

PCI: endpoint: Add helper API to get the 'next' unreserved BAR

Add an API to get the next unreserved BAR starting from a given BAR number
that can be used by the endpoint function.

Link: https://lore.kernel.org/r/20210201195809.7342-4-kishon@ti.com
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

authored by

Kishon Vijay Abraham I and committed by
Bjorn Helgaas
fa8fef0e 959a48d0

+24 -4
+22 -4
drivers/pci/endpoint/pci-epc-core.c
··· 87 87 * pci_epc_get_first_free_bar() - helper to get first unreserved BAR 88 88 * @epc_features: pci_epc_features structure that holds the reserved bar bitmap 89 89 * 90 - * Invoke to get the first unreserved BAR that can be used for endpoint 90 + * Invoke to get the first unreserved BAR that can be used by the endpoint 91 91 * function. For any incorrect value in reserved_bar return '0'. 92 92 */ 93 93 unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features 94 94 *epc_features) 95 95 { 96 + return pci_epc_get_next_free_bar(epc_features, BAR_0); 97 + } 98 + EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar); 99 + 100 + /** 101 + * pci_epc_get_next_free_bar() - helper to get unreserved BAR starting from @bar 102 + * @epc_features: pci_epc_features structure that holds the reserved bar bitmap 103 + * @bar: the starting BAR number from where unreserved BAR should be searched 104 + * 105 + * Invoke to get the next unreserved BAR starting from @bar that can be used 106 + * for endpoint function. For any incorrect value in reserved_bar return '0'. 107 + */ 108 + unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features 109 + *epc_features, enum pci_barno bar) 110 + { 96 111 unsigned long free_bar; 97 112 98 113 if (!epc_features) 99 114 return 0; 115 + 116 + /* If 'bar - 1' is a 64-bit BAR, move to the next BAR */ 117 + if ((epc_features->bar_fixed_64bit << 1) & 1 << bar) 118 + bar++; 100 119 101 120 /* Find if the reserved BAR is also a 64-bit BAR */ 102 121 free_bar = epc_features->reserved_bar & epc_features->bar_fixed_64bit; ··· 124 105 free_bar <<= 1; 125 106 free_bar |= epc_features->reserved_bar; 126 107 127 - /* Now find the free BAR */ 128 - free_bar = ffz(free_bar); 108 + free_bar = find_next_zero_bit(&free_bar, 6, bar); 129 109 if (free_bar > 5) 130 110 return 0; 131 111 132 112 return free_bar; 133 113 } 134 - EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar); 114 + EXPORT_SYMBOL_GPL(pci_epc_get_next_free_bar); 135 115 136 116 /** 137 117 * pci_epc_get_features() - get the features supported by EPC
+2
include/linux/pci-epc.h
··· 203 203 u8 func_no); 204 204 unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features 205 205 *epc_features); 206 + unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features 207 + *epc_features, enum pci_barno bar); 206 208 struct pci_epc *pci_epc_get(const char *epc_name); 207 209 void pci_epc_put(struct pci_epc *epc); 208 210