1 // SPDX-License-Identifier: GPL-2.0
3 * Numascale NumaConnect-specific PCI code
5 * Copyright (C) 2012 Numascale AS. All rights reserved.
9 * PCI accessor functions derived from mmconfig_64.c
13 #include <linux/pci.h>
14 #include <asm/pci_x86.h>
15 #include <asm/numachip/numachip.h>
17 static u8 limit __read_mostly;
19 static inline char __iomem *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn)
21 struct pci_mmcfg_region *cfg = pci_mmconfig_lookup(seg, bus);
24 return cfg->virt + (PCI_MMCFG_BUS_OFFSET(bus) | (devfn << 12));
28 static int pci_mmcfg_read_numachip(unsigned int seg, unsigned int bus,
29 unsigned int devfn, int reg, int len, u32 *value)
33 /* Why do we have this when nobody checks it. How about a BUG()!? -AK */
34 if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) {
39 /* Ensure AMD Northbridges don't decode reads to other devices */
40 if (unlikely(bus == 0 && devfn >= limit)) {
46 addr = pci_dev_base(seg, bus, devfn);
54 *value = mmio_config_readb(addr + reg);
57 *value = mmio_config_readw(addr + reg);
60 *value = mmio_config_readl(addr + reg);
68 static int pci_mmcfg_write_numachip(unsigned int seg, unsigned int bus,
69 unsigned int devfn, int reg, int len, u32 value)
73 /* Why do we have this when nobody checks it. How about a BUG()!? -AK */
74 if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095)))
77 /* Ensure AMD Northbridges don't decode writes to other devices */
78 if (unlikely(bus == 0 && devfn >= limit))
82 addr = pci_dev_base(seg, bus, devfn);
90 mmio_config_writeb(addr + reg, value);
93 mmio_config_writew(addr + reg, value);
96 mmio_config_writel(addr + reg, value);
104 static const struct pci_raw_ops pci_mmcfg_numachip = {
105 .read = pci_mmcfg_read_numachip,
106 .write = pci_mmcfg_write_numachip,
109 int __init pci_numachip_init(void)
114 /* For remote I/O, restrict bus 0 access to the actual number of AMD
115 Northbridges, which starts at device number 0x18 */
116 ret = raw_pci_read(0, 0, PCI_DEVFN(0x18, 0), 0x60, sizeof(val), &val);
120 /* HyperTransport fabric size in bits 6:4 */
121 limit = PCI_DEVFN(0x18 + ((val >> 4) & 7) + 1, 0);
123 /* Use NumaChip PCI accessors for non-extended and extended access */
124 raw_pci_ops = raw_pci_ext_ops = &pci_mmcfg_numachip;