x86/mmcfg: misc adjustments
PATCH 1/1 x86/mmcfg: misc adjustments
- fix the mapping range (end_bus_number is inclusive)
- fix the mapping base address (shifting segment by 22 was set for overlapping mappings; assuming the goal was to reduce the virtual space used when less than 256 busses are present on all segments, adding logic to determine the smallest possible shift value)
- fix PCI_MCFG_VIRT_END, and actually use it to avoid creating mappings outside the designated range
- fix address calculations (segment numbers must be converted to long to avoid truncation)
- add a way (command line option) to suppress the use of mmconfig as well as to actually use the AMD Fam10 special code
- correct __init annotations
- use xmalloc()/xmalloc_array() in favor of xmalloc_bytes()
- eliminate dead code and data
xen/arch/x86/x86_64/acpi_mmcfg.c +6 -9
@@ -48,13 +48,10 @@struct acpi_mcfg_allocation *pci_mmcfg_config;int pci_mmcfg_config_num; -static int acpi_mcfg_64bit_base_addr__initdata = FALSE; - -int acpi_parse_mcfg (struct acpi_table_header *header) +int __init acpi_parse_mcfg (struct acpi_table_header *header) {struct acpi_table_mcfg *mcfg;unsigned long i; -int config_size;if (!header)return -EINVAL ;
@@ -73,19 +70,19 @@ int acpi_parse_mcfg(struct acpi_table_hereturn -ENODEV ; } - config_size = pci_mmcfg_config_num *sizeof (*pci_mmcfg_config); - pci_mmcfg_config =xmalloc_bytes (config_size); + pci_mmcfg_config = xmalloc_array(struct acpi_mcfg_allocation, + pci_mmcfg_config_num);if (!pci_mmcfg_config) { printk(KERN_WARNING PREFIX "No memory for MCFG config tables\n");return -ENOMEM ; } -memcpy (pci_mmcfg_config, &mcfg[1 ], config_size); +memcpy (pci_mmcfg_config, &mcfg[1 ], + pci_mmcfg_config_num *sizeof (*pci_mmcfg_config));for (i =0 ; i < pci_mmcfg_config_num; ++i) { -if ((pci_mmcfg_config[i].address >0xFFFFFFFF ) && - !acpi_mcfg_64bit_base_addr) { +if (pci_mmcfg_config[i].address >0xFFFFFFFF ) { printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n");xfree (pci_mmcfg_config);
xen/arch/x86/x86_64/mmconfig.h +4 -4
@@ -81,7 +81,7 @@ static inline void mmio_config_writel(voextern int pci_mmcfg_config_num;extern struct acpi_mcfg_allocation *pci_mmcfg_config; -/* fucntion prototypes */ -int __init acpi_parse_mcfg (struct acpi_table_header *header); -int __init pci_mmcfg_arch_init (void ); -void __init pci_mmcfg_arch_free (void ); +/* function prototypes */ +int acpi_parse_mcfg (struct acpi_table_header *header); +int pci_mmcfg_arch_init (void ); +void pci_mmcfg_arch_free (void );
xen/arch/x86/x86_64/mmconfig-shared.c +32 -30
136 lines not on this page · raw message
xen/arch/x86/x86_64/mmconfig_64.c +19 -14
@@ -21,6 +21,7 @@ struct mmcfg_virt {char __iomem *virt; };static struct mmcfg_virt *pci_mmcfg_virt; +static int __initdata mmcfg_pci_segment_shift;static char __iomem *get_virt (unsigned int seg,unsigned bus) {
@@ -109,27 +110,26 @@ int pci_mmcfg_write(unsigned int seg, unstatic void __iomem *__init mcfg_ioremap (struct acpi_mcfg_allocation *cfg) { -void __iomem *addr; -unsigned long virt; -unsigned long mfn; -unsigned long size, nr_mfn; - - virt =PCI_MCFG_VIRT_START + (cfg->pci_segment * (1 <<22 )) + - (cfg->start_bus_number * (1 <<20 )); - mfn = cfg->address >>PAGE_SHIFT ; - size = (cfg->end_bus_number - cfg->start_bus_number) <<20 ; - nr_mfn = size >>PAGE_SHIFT ; +unsigned long virt, size; -map_pages_to_xen (virt, mfn, nr_mfn,PAGE_HYPERVISOR_NOCACHE ); - addr = (void __iomem *) virt; + virt =PCI_MCFG_VIRT_START + + ((unsigned long )cfg->pci_segment << mmcfg_pci_segment_shift) + + (cfg->start_bus_number <<20 ); + size = (cfg->end_bus_number - cfg->start_bus_number +1 ) <<20 ; +if (virt + size < virt || virt + size >PCI_MCFG_VIRT_END ) +return NULL ; + +map_pages_to_xen (virt, cfg->address >>PAGE_SHIFT , + size >>PAGE_SHIFT ,PAGE_HYPERVISOR_NOCACHE ); -return addr; +return (void __iomem *) virt; }int __init pci_mmcfg_arch_init (void ) {int i; - pci_mmcfg_virt =xmalloc_bytes (sizeof (*pci_mmcfg_virt) * pci_mmcfg_config_num); + + pci_mmcfg_virt = xmalloc_array(struct mmcfg_virt, pci_mmcfg_config_num);if (pci_mmcfg_virt ==NULL ) {printk (KERN_ERR "PCI: Can not allocate memory for mmconfig structures\n" );return 0 ;
@@ -138,6 +138,11 @@ int __init pci_mmcfg_arch_init(void)for (i =0 ; i < pci_mmcfg_config_num; ++i) { pci_mmcfg_virt[i].cfg = &pci_mmcfg_config[i]; +while (pci_mmcfg_config[i].end_bus_number >> mmcfg_pci_segment_shift) + ++mmcfg_pci_segment_shift; + } + mmcfg_pci_segment_shift +=20 ; +for (i =0 ; i < pci_mmcfg_config_num; ++i) { pci_mmcfg_virt[i].virt =mcfg_ioremap (&pci_mmcfg_config[i]);if (!pci_mmcfg_virt[i].virt) { printk(KERN_ERR "PCI: Cannot map mmconfig aperture for "
xen/include/asm-x86/config.h +1 -1
@@ -194,7 +194,7 @@ extern unsigned int video_mode, video_fl* - since PML4 slot has 39 bits, we limit segments to 2048 (11-bits) */ #define PCI_MCFG_VIRT_START (PML4_ADDR(257)) -#define PCI_MCFG_VIRT_END (RDWR_MPT_VIRT_START + PML4_ENTRY_BYTES) +#define PCI_MCFG_VIRT_END (PCI_MCFG_VIRT_START + PML4_ENTRY_BYTES)/* Slot 258: linear page table (guest table). */ #define LINEAR_PT_VIRT_START (PML4_ADDR(258))#define LINEAR_PT_VIRT_END (LINEAR_PT_VIRT_START + PML4_ENTRY_BYTES)