2 * mmconfig.c - Low-level direct PCI config space access via MMCONFIG
4 * This is an 64bit optimized version that always keeps the full mmconfig
5 * space mapped. This allows lockless config space operation.
9 #include <linux/init.h>
10 #include <linux/acpi.h>
13 #define MMCONFIG_APER_SIZE (256*1024*1024)
15 /* Static virtual mapping of the MMCONFIG aperture */
17 struct acpi_table_mcfg_config
*cfg
;
20 static struct mmcfg_virt
*pci_mmcfg_virt
;
22 static char *get_virt(unsigned int seg
, unsigned bus
)
25 struct acpi_table_mcfg_config
*cfg
;
29 if (cfg_num
>= pci_mmcfg_config_num
) {
30 /* Not found - fall back to type 1. This happens
31 e.g. on the internal devices of a K8 northbridge. */
34 cfg
= pci_mmcfg_virt
[cfg_num
].cfg
;
35 if (cfg
->pci_segment_group_number
!= seg
)
37 if ((cfg
->start_bus_number
<= bus
) &&
38 (cfg
->end_bus_number
>= bus
))
39 return pci_mmcfg_virt
[cfg_num
].virt
;
43 static inline char *pci_dev_base(unsigned int seg
, unsigned int bus
, unsigned int devfn
)
45 char *addr
= get_virt(seg
, bus
);
48 return addr
+ ((bus
<< 20) | (devfn
<< 12));
51 static int pci_mmcfg_read(unsigned int seg
, unsigned int bus
,
52 unsigned int devfn
, int reg
, int len
, u32
*value
)
56 /* Why do we have this when nobody checks it. How about a BUG()!? -AK */
57 if (unlikely(!value
|| (bus
> 255) || (devfn
> 255) || (reg
> 4095)))
60 addr
= pci_dev_base(seg
, bus
, devfn
);
62 return pci_conf1_read(seg
,bus
,devfn
,reg
,len
,value
);
66 *value
= readb(addr
+ reg
);
69 *value
= readw(addr
+ reg
);
72 *value
= readl(addr
+ reg
);
79 static int pci_mmcfg_write(unsigned int seg
, unsigned int bus
,
80 unsigned int devfn
, int reg
, int len
, u32 value
)
84 /* Why do we have this when nobody checks it. How about a BUG()!? -AK */
85 if (unlikely((bus
> 255) || (devfn
> 255) || (reg
> 4095)))
88 addr
= pci_dev_base(seg
, bus
, devfn
);
90 return pci_conf1_write(seg
,bus
,devfn
,reg
,len
,value
);
94 writeb(value
, addr
+ reg
);
97 writew(value
, addr
+ reg
);
100 writel(value
, addr
+ reg
);
107 static struct pci_raw_ops pci_mmcfg
= {
108 .read
= pci_mmcfg_read
,
109 .write
= pci_mmcfg_write
,
112 static int __init
pci_mmcfg_init(void)
116 if ((pci_probe
& PCI_PROBE_MMCONF
) == 0)
119 acpi_table_parse(ACPI_MCFG
, acpi_parse_mcfg
);
120 if ((pci_mmcfg_config_num
== 0) ||
121 (pci_mmcfg_config
== NULL
) ||
122 (pci_mmcfg_config
[0].base_address
== 0))
125 /* RED-PEN i386 doesn't do _nocache right now */
126 pci_mmcfg_virt
= kmalloc(sizeof(*pci_mmcfg_virt
) * pci_mmcfg_config_num
, GFP_KERNEL
);
127 if (pci_mmcfg_virt
== NULL
) {
128 printk("PCI: Can not allocate memory for mmconfig structures\n");
131 for (i
= 0; i
< pci_mmcfg_config_num
; ++i
) {
132 pci_mmcfg_virt
[i
].cfg
= &pci_mmcfg_config
[i
];
133 pci_mmcfg_virt
[i
].virt
= ioremap_nocache(pci_mmcfg_config
[i
].base_address
, MMCONFIG_APER_SIZE
);
134 if (!pci_mmcfg_virt
[i
].virt
) {
135 printk("PCI: Cannot map mmconfig aperture for segment %d\n",
136 pci_mmcfg_config
[i
].pci_segment_group_number
);
139 printk(KERN_INFO
"PCI: Using MMCONFIG at %x\n", pci_mmcfg_config
[i
].base_address
);
142 raw_pci_ops
= &pci_mmcfg
;
143 pci_probe
= (pci_probe
& ~PCI_PROBE_MASK
) | PCI_PROBE_MMCONF
;
148 arch_initcall(pci_mmcfg_init
);
This page took 0.048981 seconds and 5 git commands to generate.