From: "Jan Beulich" Subject: [PATCH 1/2] hvmloader: also cover PCI MMIO ranges above 4G with UC MTRR ranges Date: Mon, 19 May 2014 14:12:57 +0100 Message-ID: <537A1F790200007800013A4D@mail.emea.novell.com> References: <537A1D1E0200007800013A2C@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part0B392F49.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WmNNI-0005Cw-DE for xen-devel@lists.xenproject.org; Mon, 19 May 2014 13:13:04 +0000 In-Reply-To: <537A1D1E0200007800013A2C@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Ian Campbell , Ian Jackson , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part0B392F49.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline When adding support for BAR assignments to addresses above 4G, the MTRR side of things was left out. Additionally the MMIO ranges in the DSDT's \_SB.PCI0._CRS were having memory types not matching the ones put into MTRRs: The legacy VGA range is supposed to be WC, and the other ones should be UC. Signed-off-by: Jan Beulich --- a/tools/firmware/hvmloader/acpi/build.c +++ b/tools/firmware/hvmloader/acpi/build.c @@ -53,6 +53,7 @@ struct acpi_info { uint32_t madt_csum_addr; /* 12 - Address of MADT checksum */ uint32_t madt_lapic0_addr; /* 16 - Address of first MADT LAPIC = struct */ uint32_t vm_gid_addr; /* 20 - Address of VM generation id = buffer */ + uint64_t pci_hi_min, pci_hi_len; /* 24, 32 - PCI I/O hole boundaries = */ }; =20 /* Number of processor objects in the chosen DSDT. */ @@ -541,6 +542,11 @@ void acpi_build_tables(struct acpi_confi acpi_info->hpet_present =3D hpet_exists(ACPI_HPET_ADDRESS); acpi_info->pci_min =3D pci_mem_start; acpi_info->pci_len =3D pci_mem_end - pci_mem_start; + if ( pci_hi_mem_end > pci_hi_mem_start ) + { + acpi_info->pci_hi_min =3D pci_hi_mem_start; + acpi_info->pci_hi_len =3D pci_hi_mem_end - pci_hi_mem_start; + } =20 return; =20 --- a/tools/firmware/hvmloader/acpi/dsdt.asl +++ b/tools/firmware/hvmloader/acpi/dsdt.asl @@ -45,7 +45,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2,=20 Scope (\_SB) { /* ACPI_INFO_PHYSICAL_ADDRESS =3D=3D 0xFC000000 */ - OperationRegion(BIOS, SystemMemory, 0xFC000000, 24) + OperationRegion(BIOS, SystemMemory, 0xFC000000, 40) Field(BIOS, ByteAcc, NoLock, Preserve) { UAR1, 1, UAR2, 1, @@ -56,7 +56,9 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2,=20 PLEN, 32, MSUA, 32, /* MADT checksum address */ MAPA, 32, /* MADT LAPIC0 address */ - VGIA, 32 /* VM generation id address */ + VGIA, 32, /* VM generation id address */ + HMIN, 64, + HLEN, 64 } =20 /* Fix HCT test for 0x400 pci memory: @@ -136,7 +138,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2,=20 /* reserve memory for pci devices */ DWordMemory( ResourceProducer, PosDecode, MinFixed, MaxFixed, - Cacheable, ReadWrite, + WriteCombining, ReadWrite, 0x00000000, 0x000A0000, 0x000BFFFF, @@ -145,13 +147,24 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2,=20 =20 DWordMemory( ResourceProducer, PosDecode, MinFixed, MaxFixed, - Cacheable, ReadWrite, + NonCacheable, ReadWrite, 0x00000000, 0xF0000000, 0xF4FFFFFF, 0x00000000, 0x05000000, ,, _Y01) + + QWordMemory ( + ResourceProducer, PosDecode, MinFixed, MaxFixed, + NonCacheable, ReadWrite, + 0x0000000000000000, + 0x0000000000000000, + 0x0000000000000000, + 0x0000000000000000, + 0x0000000000000000, + ,, _Y02) + }) =20 CreateDWordField(PRT0, \_SB.PCI0._CRS._Y01._MIN, MMIN) @@ -163,6 +176,17 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2,=20 Add(MMIN, MLEN, MMAX) Subtract(MMAX, One, MMAX) =20 + CreateQWordField(PRT0, \_SB.PCI0._CRS._Y02._MIN, HMIN) + CreateQWordField(PRT0, \_SB.PCI0._CRS._Y02._MAX, HMAX) + CreateQWordField(PRT0, \_SB.PCI0._CRS._Y02._LEN, HLEN) + + Store(\_SB.HMIN, HMIN) + Store(\_SB.HLEN, HLEN) + Add(HMIN, HLEN, HMAX) + If(LOr(HMIN, HLEN)) { + Subtract(HMAX, One, HMAX) + } + Return (PRT0) } =20 --- a/tools/firmware/hvmloader/cacheattr.c +++ b/tools/firmware/hvmloader/cacheattr.c @@ -97,8 +97,7 @@ void cacheattr_init(void) nr_var_ranges =3D (uint8_t)mtrr_cap; if ( nr_var_ranges !=3D 0 ) { - unsigned long base =3D pci_mem_start, size; - int i; + uint64_t base =3D pci_mem_start, size; =20 for ( i =3D 0; (base !=3D pci_mem_end) && (i < nr_var_ranges); = i++ ) { @@ -109,8 +108,22 @@ void cacheattr_init(void) size >>=3D 1; =20 wrmsr(MSR_MTRRphysBase(i), base); - wrmsr(MSR_MTRRphysMask(i), - (~(uint64_t)(size-1) & addr_mask) | (1u << 11)); + wrmsr(MSR_MTRRphysMask(i), (~(size - 1) & addr_mask) | (1u << = 11)); + + base +=3D size; + } + + for ( base =3D pci_hi_mem_start; + (base !=3D pci_hi_mem_end) && (i < nr_var_ranges); i++ ) + { + size =3D PAGE_SIZE; + while ( !(base & size) ) + size <<=3D 1; + while ( (base + size < base) || (base + size > pci_hi_mem_end)= ) + size >>=3D 1; + + wrmsr(MSR_MTRRphysBase(i), base); + wrmsr(MSR_MTRRphysMask(i), (~(size - 1) & addr_mask) | (1u << = 11)); =20 base +=3D size; } --- a/tools/firmware/hvmloader/config.h +++ b/tools/firmware/hvmloader/config.h @@ -57,7 +57,7 @@ extern struct bios_config ovmf_config; #define PCI_MEM_END 0xfc000000 =20 extern unsigned long pci_mem_start, pci_mem_end; - +extern uint64_t pci_hi_mem_start, pci_hi_mem_end; =20 /* Memory map. */ #define SCRATCH_PHYSICAL_ADDRESS 0x00010000 --- a/tools/firmware/hvmloader/pci.c +++ b/tools/firmware/hvmloader/pci.c @@ -32,6 +32,7 @@ =20 unsigned long pci_mem_start =3D PCI_MEM_START; unsigned long pci_mem_end =3D PCI_MEM_END; +uint64_t pci_hi_mem_start =3D 0, pci_hi_mem_end =3D 0; =20 enum virtual_vga virtual_vga =3D VGA_none; unsigned long igd_opregion_pgbase =3D 0; @@ -345,9 +346,8 @@ void pci_setup(void) if ( high_mem_resource.base & (bar_sz - 1) ) high_mem_resource.base =3D high_mem_resource.base = -=20 (high_mem_resource.base & (bar_sz - 1)) + bar_sz; - else - high_mem_resource.base =3D high_mem_resource.base = -=20 - (high_mem_resource.base & (bar_sz - 1)); + if ( !pci_hi_mem_start ) + pci_hi_mem_start =3D high_mem_resource.base; resource =3D &high_mem_resource; bar_data &=3D ~PCI_BASE_ADDRESS_MEM_MASK; }=20 @@ -398,6 +398,16 @@ void pci_setup(void) pci_writew(devfn, PCI_COMMAND, cmd); } =20 + if ( pci_hi_mem_start ) + { + /* + * Make end address alignment match the start address one's so = that + * fewer variable range MTRRs are needed to cover the range. + */ + pci_hi_mem_end =3D ((high_mem_resource.base - 1) | + ((pci_hi_mem_start & -pci_hi_mem_start) - 1)) + = 1; + } + if ( vga_devfn !=3D 256 ) { /* --=__Part0B392F49.1__= Content-Type: text/plain; name="hvmloader-PCI-above-4G.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="hvmloader-PCI-above-4G.patch" hvmloader: also cover PCI MMIO ranges above 4G with UC MTRR ranges=0A=0AWhe= n adding support for BAR assignments to addresses above 4G, the MTRR=0Aside= of things was left out.=0A=0AAdditionally the MMIO ranges in the DSDT's = \_SB.PCI0._CRS were having=0Amemory types not matching the ones put into = MTRRs: The legacy VGA range=0Ais supposed to be WC, and the other ones = should be UC.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/tools/firmware/hvmloader/acpi/build.c=0A+++ b/tools/firmware/hvmloader/ac= pi/build.c=0A@@ -53,6 +53,7 @@ struct acpi_info {=0A uint32_t = madt_csum_addr; /* 12 - Address of MADT checksum */=0A uint32_t = madt_lapic0_addr; /* 16 - Address of first MADT LAPIC struct */=0A = uint32_t vm_gid_addr; /* 20 - Address of VM generation id buffer = */=0A+ uint64_t pci_hi_min, pci_hi_len; /* 24, 32 - PCI I/O hole = boundaries */=0A };=0A =0A /* Number of processor objects in the chosen = DSDT. */=0A@@ -541,6 +542,11 @@ void acpi_build_tables(struct acpi_confi=0A= acpi_info->hpet_present =3D hpet_exists(ACPI_HPET_ADDRESS);=0A = acpi_info->pci_min =3D pci_mem_start;=0A acpi_info->pci_len =3D = pci_mem_end - pci_mem_start;=0A+ if ( pci_hi_mem_end > pci_hi_mem_start = )=0A+ {=0A+ acpi_info->pci_hi_min =3D pci_hi_mem_start;=0A+ = acpi_info->pci_hi_len =3D pci_hi_mem_end - pci_hi_mem_start;=0A+ }=0A = =0A return;=0A =0A--- a/tools/firmware/hvmloader/acpi/dsdt.asl=0A+++ = b/tools/firmware/hvmloader/acpi/dsdt.asl=0A@@ -45,7 +45,7 @@ DefinitionBloc= k ("DSDT.aml", "DSDT", 2, =0A Scope (\_SB)=0A {=0A /* = ACPI_INFO_PHYSICAL_ADDRESS =3D=3D 0xFC000000 */=0A- OperationRegion(B= IOS, SystemMemory, 0xFC000000, 24)=0A+ OperationRegion(BIOS, = SystemMemory, 0xFC000000, 40)=0A Field(BIOS, ByteAcc, NoLock, = Preserve) {=0A UAR1, 1,=0A UAR2, 1,=0A@@ -56,7 +56,9 = @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, =0A PLEN, 32,=0A = MSUA, 32, /* MADT checksum address */=0A MAPA, 32, /* = MADT LAPIC0 address */=0A- VGIA, 32 /* VM generation id address = */=0A+ VGIA, 32, /* VM generation id address */=0A+ = HMIN, 64,=0A+ HLEN, 64=0A }=0A =0A /* Fix HCT = test for 0x400 pci memory:=0A@@ -136,7 +138,7 @@ DefinitionBlock ("DSDT.aml= ", "DSDT", 2, =0A /* reserve memory for pci devices = */=0A DWordMemory(=0A = ResourceProducer, PosDecode, MinFixed, MaxFixed,=0A- = Cacheable, ReadWrite,=0A+ WriteCombining, = ReadWrite,=0A 0x00000000,=0A = 0x000A0000,=0A 0x000BFFFF,=0A@@ -145,13 +147,24 = @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, =0A =0A = DWordMemory(=0A ResourceProducer, PosDecode, = MinFixed, MaxFixed,=0A- Cacheable, ReadWrite,=0A+ = NonCacheable, ReadWrite,=0A = 0x00000000,=0A 0xF0000000,=0A = 0xF4FFFFFF,=0A 0x00000000,=0A = 0x05000000,=0A ,, _Y01)=0A+=0A+ = QWordMemory (=0A+ ResourceProducer, PosDecode,= MinFixed, MaxFixed,=0A+ NonCacheable, ReadWrite,=0A= + 0x0000000000000000,=0A+ = 0x0000000000000000,=0A+ 0x0000000000000000,=0A+ = 0x0000000000000000,=0A+ = 0x0000000000000000,=0A+ ,, _Y02)=0A+=0A = })=0A =0A CreateDWordField(PRT0, \_SB.PCI0._CRS._Y01._M= IN, MMIN)=0A@@ -163,6 +176,17 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, = =0A Add(MMIN, MLEN, MMAX)=0A Subtract(MMAX,= One, MMAX)=0A =0A+ CreateQWordField(PRT0, \_SB.PCI0._CRS._Y= 02._MIN, HMIN)=0A+ CreateQWordField(PRT0, \_SB.PCI0._CRS._Y0= 2._MAX, HMAX)=0A+ CreateQWordField(PRT0, \_SB.PCI0._CRS._Y02= ._LEN, HLEN)=0A+=0A+ Store(\_SB.HMIN, HMIN)=0A+ = Store(\_SB.HLEN, HLEN)=0A+ Add(HMIN, HLEN, HMAX)=0A+ = If(LOr(HMIN, HLEN)) {=0A+ Subtract(HMAX, = One, HMAX)=0A+ }=0A+=0A Return (PRT0)=0A = }=0A =0A--- a/tools/firmware/hvmloader/cacheattr.c=0A+++ = b/tools/firmware/hvmloader/cacheattr.c=0A@@ -97,8 +97,7 @@ void cacheattr_i= nit(void)=0A nr_var_ranges =3D (uint8_t)mtrr_cap;=0A if ( = nr_var_ranges !=3D 0 )=0A {=0A- unsigned long base =3D = pci_mem_start, size;=0A- int i;=0A+ uint64_t base =3D = pci_mem_start, size;=0A =0A for ( i =3D 0; (base !=3D pci_mem_end) = && (i < nr_var_ranges); i++ )=0A {=0A@@ -109,8 +108,22 @@ void = cacheattr_init(void)=0A size >>=3D 1;=0A =0A = wrmsr(MSR_MTRRphysBase(i), base);=0A- wrmsr(MSR_MTRRphysMask(i),= =0A- (~(uint64_t)(size-1) & addr_mask) | (1u << 11));=0A+ = wrmsr(MSR_MTRRphysMask(i), (~(size - 1) & addr_mask) | (1u << = 11));=0A+=0A+ base +=3D size;=0A+ }=0A+=0A+ for ( = base =3D pci_hi_mem_start;=0A+ (base !=3D pci_hi_mem_end) && = (i < nr_var_ranges); i++ )=0A+ {=0A+ size =3D PAGE_SIZE;= =0A+ while ( !(base & size) )=0A+ size <<=3D = 1;=0A+ while ( (base + size < base) || (base + size > pci_hi_mem= _end) )=0A+ size >>=3D 1;=0A+=0A+ wrmsr(MSR_MTRRp= hysBase(i), base);=0A+ wrmsr(MSR_MTRRphysMask(i), (~(size - 1) = & addr_mask) | (1u << 11));=0A =0A base +=3D size;=0A = }=0A--- a/tools/firmware/hvmloader/config.h=0A+++ b/tools/firmware/hvmloade= r/config.h=0A@@ -57,7 +57,7 @@ extern struct bios_config ovmf_config;=0A = #define PCI_MEM_END 0xfc000000=0A =0A extern unsigned long = pci_mem_start, pci_mem_end;=0A-=0A+extern uint64_t pci_hi_mem_start, = pci_hi_mem_end;=0A =0A /* Memory map. */=0A #define SCRATCH_PHYSICAL_ADDRES= S 0x00010000=0A--- a/tools/firmware/hvmloader/pci.c=0A+++ b/tools/firm= ware/hvmloader/pci.c=0A@@ -32,6 +32,7 @@=0A =0A unsigned long pci_mem_start= =3D PCI_MEM_START;=0A unsigned long pci_mem_end =3D PCI_MEM_END;=0A+uint64= _t pci_hi_mem_start =3D 0, pci_hi_mem_end =3D 0;=0A =0A enum virtual_vga = virtual_vga =3D VGA_none;=0A unsigned long igd_opregion_pgbase =3D 0;=0A@@ = -345,9 +346,8 @@ void pci_setup(void)=0A if ( high_mem_reso= urce.base & (bar_sz - 1) )=0A high_mem_resource.base = =3D high_mem_resource.base - =0A (high_mem_resource= .base & (bar_sz - 1)) + bar_sz;=0A- else=0A- = high_mem_resource.base =3D high_mem_resource.base - =0A- = (high_mem_resource.base & (bar_sz - 1));=0A+ if ( = !pci_hi_mem_start )=0A+ pci_hi_mem_start =3D high_mem_re= source.base;=0A resource =3D &high_mem_resource;=0A = bar_data &=3D ~PCI_BASE_ADDRESS_MEM_MASK;=0A } =0A@@ = -398,6 +398,16 @@ void pci_setup(void)=0A pci_writew(devfn, = PCI_COMMAND, cmd);=0A }=0A =0A+ if ( pci_hi_mem_start )=0A+ = {=0A+ /*=0A+ * Make end address alignment match the start = address one's so that=0A+ * fewer variable range MTRRs are needed = to cover the range.=0A+ */=0A+ pci_hi_mem_end =3D ((high_mem= _resource.base - 1) |=0A+ ((pci_hi_mem_start & = -pci_hi_mem_start) - 1)) + 1;=0A+ }=0A+=0A if ( vga_devfn !=3D 256 = )=0A {=0A /*=0A --=__Part0B392F49.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part0B392F49.1__=--