Commit 6f3d5d3cc4b1447578ae8484166bbc34a64150c5

Authored by Michael Ellerman
Committed by Paul Mackerras
1 parent a0a428e300

[POWERPC] Add a helper for calculating RTAS "config_addr" parameters

Several RTAS calls take a "config_addr" parameter, which is a particular
way of specifying a PCI busno, devfn and register number into a 32-bit word.
Currently these are open-coded, and I'll be adding another soon, replace
them with a helper that encapsulates the logic. Be more strict about masking
the busno too, just in case.

Booted on P5 LPAR.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>

Showing 2 changed files with 18 additions and 4 deletions Side-by-side Diff

arch/powerpc/kernel/rtas_pci.c
... ... @@ -81,8 +81,7 @@
81 81 if (!config_access_valid(pdn, where))
82 82 return PCIBIOS_BAD_REGISTER_NUMBER;
83 83  
84   - addr = ((where & 0xf00) << 20) | (pdn->busno << 16) |
85   - (pdn->devfn << 8) | (where & 0xff);
  84 + addr = rtas_config_addr(pdn->busno, pdn->devfn, where);
86 85 buid = pdn->phb->buid;
87 86 if (buid) {
88 87 ret = rtas_call(ibm_read_pci_config, 4, 2, &returnval,
... ... @@ -134,8 +133,7 @@
134 133 if (!config_access_valid(pdn, where))
135 134 return PCIBIOS_BAD_REGISTER_NUMBER;
136 135  
137   - addr = ((where & 0xf00) << 20) | (pdn->busno << 16) |
138   - (pdn->devfn << 8) | (where & 0xff);
  136 + addr = rtas_config_addr(pdn->busno, pdn->devfn, where);
139 137 buid = pdn->phb->buid;
140 138 if (buid) {
141 139 ret = rtas_call(ibm_write_pci_config, 5, 1, NULL, addr,
include/asm-powerpc/rtas.h
... ... @@ -230,6 +230,22 @@
230 230  
231 231 #define GLOBAL_INTERRUPT_QUEUE 9005
232 232  
  233 +/**
  234 + * rtas_config_addr - Format a busno, devfn and reg for RTAS.
  235 + * @busno: The bus number.
  236 + * @devfn: The device and function number as encoded by PCI_DEVFN().
  237 + * @reg: The register number.
  238 + *
  239 + * This function encodes the given busno, devfn and register number as
  240 + * required for RTAS calls that take a "config_addr" parameter.
  241 + * See PAPR requirement 7.3.4-1 for more info.
  242 + */
  243 +static inline u32 rtas_config_addr(int busno, int devfn, int reg)
  244 +{
  245 + return ((reg & 0xf00) << 20) | ((busno & 0xff) << 16) |
  246 + (devfn << 8) | (reg & 0xff);
  247 +}
  248 +
233 249 #endif /* __KERNEL__ */
234 250 #endif /* _POWERPC_RTAS_H */