diff options
author | jkim <jkim@FreeBSD.org> | 2012-12-01 00:56:19 +0000 |
---|---|---|
committer | jkim <jkim@FreeBSD.org> | 2012-12-01 00:56:19 +0000 |
commit | caa6f5a7e68aecd7aed922bb2ec4b2ff6fb40a52 (patch) | |
tree | 32dd64387dab2d4897dd095da8de193b5eec1f27 /sys/i386/pci/pci_cfgreg.c | |
parent | 029de4582ccac87dd64ca5ad93a2a57f92b108e7 (diff) | |
download | FreeBSD-src-caa6f5a7e68aecd7aed922bb2ec4b2ff6fb40a52.zip FreeBSD-src-caa6f5a7e68aecd7aed922bb2ec4b2ff6fb40a52.tar.gz |
Remove duplicate code. Reduce diff between amd64 and i386.
Diffstat (limited to 'sys/i386/pci/pci_cfgreg.c')
-rw-r--r-- | sys/i386/pci/pci_cfgreg.c | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/sys/i386/pci/pci_cfgreg.c b/sys/i386/pci/pci_cfgreg.c index 45b4c6f..14558d8 100644 --- a/sys/i386/pci/pci_cfgreg.c +++ b/sys/i386/pci/pci_cfgreg.c @@ -610,25 +610,29 @@ pcie_cfgregopen(uint64_t base, uint8_t minbus, uint8_t maxbus) } #endif /* !XEN */ -#define PCIE_PADDR(bar, reg, bus, slot, func) \ - ((bar) | \ - (((bus) & 0xff) << 20) | \ +#define PCIE_PADDR(base, reg, bus, slot, func) \ + ((base) + \ + ((((bus) & 0xff) << 20) | \ (((slot) & 0x1f) << 15) | \ (((func) & 0x7) << 12) | \ - ((reg) & 0xfff)) + ((reg) & 0xfff))) -/* - * Find an element in the cache that matches the physical page desired, or - * create a new mapping from the least recently used element. - * A very simple LRU algorithm is used here, does it need to be more - * efficient? - */ -static __inline struct pcie_cfg_elem * -pciereg_findelem(vm_paddr_t papage) +static __inline vm_offset_t +pciereg_findaddr(int bus, unsigned slot, unsigned func, unsigned reg) { struct pcie_cfg_list *pcielist; struct pcie_cfg_elem *elem; + vm_paddr_t pa, papage; + + pa = PCIE_PADDR(pcie_base, reg, bus, slot, func); + papage = pa & ~PAGE_MASK; + /* + * Find an element in the cache that matches the physical page desired, + * or create a new mapping from the least recently used element. + * A very simple LRU algorithm is used here, does it need to be more + * efficient? + */ pcielist = &pcie_list[PCPU_GET(cpuid)]; TAILQ_FOREACH(elem, pcielist, elem) { if (elem->papage == papage) @@ -649,7 +653,7 @@ pciereg_findelem(vm_paddr_t papage) TAILQ_REMOVE(pcielist, elem, elem); TAILQ_INSERT_HEAD(pcielist, elem, elem); } - return (elem); + return (elem->vapage | (pa & PAGE_MASK)); } /* @@ -664,9 +668,7 @@ static int pciereg_cfgread(int bus, unsigned slot, unsigned func, unsigned reg, unsigned bytes) { - struct pcie_cfg_elem *elem; vm_offset_t va; - vm_paddr_t pa, papage; int data = -1; if (bus < pcie_minbus || bus > pcie_maxbus || slot > PCI_SLOTMAX || @@ -674,10 +676,7 @@ pciereg_cfgread(int bus, unsigned slot, unsigned func, unsigned reg, return (-1); critical_enter(); - pa = PCIE_PADDR(pcie_base, reg, bus, slot, func); - papage = pa & ~PAGE_MASK; - elem = pciereg_findelem(papage); - va = elem->vapage | (pa & PAGE_MASK); + va = pciereg_findaddr(bus, slot, func, reg); switch (bytes) { case 4: @@ -702,19 +701,14 @@ static void pciereg_cfgwrite(int bus, unsigned slot, unsigned func, unsigned reg, int data, unsigned bytes) { - struct pcie_cfg_elem *elem; vm_offset_t va; - vm_paddr_t pa, papage; if (bus < pcie_minbus || bus > pcie_maxbus || slot > PCI_SLOTMAX || func > PCI_FUNCMAX || reg > PCIE_REGMAX) return; critical_enter(); - pa = PCIE_PADDR(pcie_base, reg, bus, slot, func); - papage = pa & ~PAGE_MASK; - elem = pciereg_findelem(papage); - va = elem->vapage | (pa & PAGE_MASK); + va = pciereg_findaddr(bus, slot, func, reg); switch (bytes) { case 4: |