From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NN5TR-0003tn-UC for mharc-grub-devel@gnu.org; Tue, 22 Dec 2009 09:12:29 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NN5TQ-0003sM-ES for grub-devel@gnu.org; Tue, 22 Dec 2009 09:12:28 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NN5TL-0003m7-MC for grub-devel@gnu.org; Tue, 22 Dec 2009 09:12:28 -0500 Received: from [199.232.76.173] (port=35210 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NN5TL-0003lu-DO for grub-devel@gnu.org; Tue, 22 Dec 2009 09:12:23 -0500 Received: from fg-out-1718.google.com ([72.14.220.159]:55480) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NN5TK-0004VZ-Ms for grub-devel@gnu.org; Tue, 22 Dec 2009 09:12:23 -0500 Received: by fg-out-1718.google.com with SMTP id 16so2205590fgg.12 for ; Tue, 22 Dec 2009 06:12:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:x-enigmail-version:content-type; bh=DgrvSlJpmOlLGBmWVVXw1sSOYXC9oKu5PY5+ARdgVOs=; b=jDWTp/DxTloc/tSqPdIyrKESaYTMADm+5bTaPIsi/kGYhDrNkxGacMO8UoW5EGCcgU GsJE5cQmyKLo/sf8t4ZaEqDW/1QAPFNd51C9Byor7DZbUgwX+Th6UUkGndK5rEWeVzdi ssqZCwB0KW2palUHgmz1jXPTGm27+jZdR9WT8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type; b=WKGIZhFCS3QIVbysSaTq8PY5KHOvISlnlg/7W0VkYEU5nRuVLTFTcInCq2VRpC9EoA yAElqU46wU1ktNk30Z3DJ90O8p3wLNrvlgAcNMUC9A1Q2zD4A4ma2HA98jv8f0N750bn VVY9PPJZOMsBay+gVirCBE2ba4D+R0XoIoxhU= Received: by 10.87.64.37 with SMTP id r37mr1355144fgk.53.1261491140146; Tue, 22 Dec 2009 06:12:20 -0800 (PST) Received: from debian.bg45.phnet (27.65.202.62.cust.bluewin.ch [62.202.65.27]) by mx.google.com with ESMTPS id e11sm15034898fga.9.2009.12.22.06.12.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 22 Dec 2009 06:12:19 -0800 (PST) Message-ID: <4B30D3B9.2010705@gmail.com> Date: Tue, 22 Dec 2009 15:12:09 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109) MIME-Version: 1.0 To: The development of GRUB 2 X-Enigmail-Version: 0.95.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig5AD2551B5863670264197F79" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [PATCH] byte-addressable grub_pci_make_address X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 14:12:28 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig5AD2551B5863670264197F79 Content-Type: multipart/mixed; boundary="------------040005070201070809020105" This is a multi-part message in MIME format. --------------040005070201070809020105 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, I noticed that grub_pci_make_address addresses register on dword boundaries whereas some important byte registers aren't dword-aligned. It's impossible to access such registers in opaque way which is required when using grub-emu with PCI support. Here is a fix --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------040005070201070809020105 Content-Type: text/x-diff; name="pciclean.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="pciclean.diff" =3D=3D=3D added file 'ChangeLog.pciclean' --- ChangeLog.pciclean 1970-01-01 00:00:00 +0000 +++ ChangeLog.pciclean 2009-12-22 14:07:47 +0000 @@ -0,0 +1,52 @@ +2009-12-22 Vladimir Serbinenko + + Byte-addressable PCI configuration space. + + * bus/pci.c (grub_pci_make_address): Use byte address instead of + dword address. + (grub_pci_iterate): Use macroses GRUB_PCI_REG_PCI_ID and + GRUB_PCI_REG_CACHELINE. + * bus/usb/ohci.c (grub_ohci_pci_iter): Use macroses + GRUB_PCI_REG_CLASS and GRUB_PCI_REG_ADDRESS_REG0. + * bus/usb/uhci.c (grub_ohci_pci_iter): Use macroses + GRUB_PCI_REG_CLASS and GRUB_PCI_REG_ADDRESS_REG4. + * commands/efi/fixvideo.c (scan_card): Use macros GRUB_PCI_REG_CLASS. + * commands/efi/loadbios.c (enable_rom_area): Pass byte-address to + grub_pci_make_address. + (lock_rom_area): Likewise. + * commands/lspci.c (grub_lspci_iter): Use macroses + GRUB_PCI_REG_CLASS and GRUB_PCI_REG_ADDRESSES. Handle byte-addressing + of grub_pci_make_address. + * disk/ata.c (grub_ata_pciinit): Likewise. + * include/grub/pci.h (GRUB_PCI_REG_PCI_ID): New macro. + (GRUB_PCI_REG_VENDOR): Likewise. + (GRUB_PCI_REG_DEVICE): Likewise. + (GRUB_PCI_REG_COMMAND): Likewise. + (GRUB_PCI_REG_STATUS): Likewise. + (GRUB_PCI_REG_REVISION): Likewise. + (GRUB_PCI_REG_CLASS): Likewise. + (GRUB_PCI_REG_CACHELINE): Likewise. + (GRUB_PCI_REG_LAT_TIMER): Likewise. + (GRUB_PCI_REG_HEADER_TYPE): Likewise. + (GRUB_PCI_REG_BIST): Likewise. + (GRUB_PCI_REG_ADDRESSES): Likewise. + (GRUB_PCI_REG_ADDRESS_REG): Likewise. + (GRUB_PCI_REG_ADDRESS_REG): Likewise. + (GRUB_PCI_REG_ADDRESS_REG): Likewise. + (GRUB_PCI_REG_ADDRESS_REG): Likewise. + (GRUB_PCI_REG_ADDRESS_REG): Likewise. + (GRUB_PCI_REG_ADDRESS_REG): Likewise. + (GRUB_PCI_REG_CIS_POINTER): Likewise. + (GRUB_PCI_REG_SUBVENDOR): Likewise. + (GRUB_PCI_REG_SUBSYSTEM): Likewise. + (GRUB_PCI_REG_ROM_ADDRESS): Likewise. + (GRUB_PCI_REG_CAP_POINTER): Likewise. + (GRUB_PCI_REG_IRQ_LINE): Likewise. + (GRUB_PCI_REG_IRQ_PIN): Likewise. + (GRUB_PCI_REG_MIN_GNT): Likewise. + (GRUB_PCI_REG_MAX_LAT): Likewise. + * loader/i386/efi/linux.c (find_framebuf): Use GRUB_PCI_REG_CLASS. + * loader/i386/efi/xnu.c (find_framebuf): Likewise. + * video/efi_uga.c (find_framebuf): Likewise. + * util/pci.c (grub_pci_make_address): Use byte-addressed configuration + space. =3D=3D=3D modified file 'bus/pci.c' --- bus/pci.c 2009-10-14 08:11:59 +0000 +++ bus/pci.c 2009-12-22 12:02:51 +0000 @@ -24,7 +24,7 @@ grub_pci_make_address (grub_pci_device_t dev, int reg) { return (1 << 31) | (dev.bus << 16) | (dev.device << 11) - | (dev.function << 8) | (reg << 2); + | (dev.function << 8) | reg; } =20 void @@ -41,7 +41,7 @@ { for (dev.function =3D 0; dev.function < 8; dev.function++) { - addr =3D grub_pci_make_address (dev, 0); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_PCI_ID); id =3D grub_pci_read (addr); =20 /* Check if there is a device present. */ @@ -54,7 +54,7 @@ /* Probe only func =3D 0 if the device if not multifunction */ if (dev.function =3D=3D 0) { - addr =3D grub_pci_make_address (dev, 3); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CACHELINE); hdr =3D grub_pci_read (addr); if (!(hdr & 0x800000)) break; =3D=3D=3D modified file 'bus/usb/ohci.c' --- bus/usb/ohci.c 2009-10-14 08:11:59 +0000 +++ bus/usb/ohci.c 2009-12-22 11:52:59 +0000 @@ -126,7 +126,7 @@ grub_uint32_t revision; grub_uint32_t frame_interval; =20 - addr =3D grub_pci_make_address (dev, 2); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); class_code =3D grub_pci_read (addr) >> 8; =20 interf =3D class_code & 0xFF; @@ -138,7 +138,7 @@ return 0; =20 /* Determine IO base address. */ - addr =3D grub_pci_make_address (dev, 4); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); base =3D grub_pci_read (addr); =20 #if 0 =3D=3D=3D modified file 'bus/usb/uhci.c' --- bus/usb/uhci.c 2009-12-22 09:15:59 +0000 +++ bus/usb/uhci.c 2009-12-22 11:51:58 +0000 @@ -150,7 +150,7 @@ struct grub_uhci *u; int i; =20 - addr =3D grub_pci_make_address (dev, 2); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); class_code =3D grub_pci_read (addr) >> 8; =20 interf =3D class_code & 0xFF; @@ -162,7 +162,7 @@ return 0; =20 /* Determine IO base address. */ - addr =3D grub_pci_make_address (dev, 8); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG4); base =3D grub_pci_read (addr); /* Stop if there is no IO space base address defined. */ if (! (base & 1)) =3D=3D=3D modified file 'commands/efi/fixvideo.c' --- commands/efi/fixvideo.c 2009-11-30 18:09:11 +0000 +++ commands/efi/fixvideo.c 2009-12-22 11:54:44 +0000 @@ -42,7 +42,7 @@ { grub_pci_address_t addr; =20 - addr =3D grub_pci_make_address (dev, 2); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); if (grub_pci_read_byte (addr + 3) =3D=3D 0x3) { struct grub_video_patch *p =3D video_patches; =3D=3D=3D modified file 'commands/efi/loadbios.c' --- commands/efi/loadbios.c 2009-12-21 22:06:04 +0000 +++ commands/efi/loadbios.c 2009-12-22 12:03:12 +0000 @@ -50,7 +50,7 @@ return 0; } =20 - addr =3D grub_pci_make_address (dev, 36); + addr =3D grub_pci_make_address (dev, 144); grub_pci_write_byte (addr++, 0x30); grub_pci_write_byte (addr++, 0x33); grub_pci_write_byte (addr++, 0x33); @@ -76,7 +76,7 @@ grub_pci_address_t addr; grub_pci_device_t dev =3D { .bus =3D 0, .device =3D 0, .function =3D 0= }; =20 - addr =3D grub_pci_make_address (dev, 36); + addr =3D grub_pci_make_address (dev, 144); grub_pci_write_byte (addr++, 0x10); grub_pci_write_byte (addr++, 0x11); grub_pci_write_byte (addr++, 0x11); =3D=3D=3D modified file 'commands/lspci.c' --- commands/lspci.c 2009-12-22 09:41:53 +0000 +++ commands/lspci.c 2009-12-22 11:59:48 +0000 @@ -134,7 +134,7 @@ grub_printf ("%02x:%02x.%x %04x:%04x", grub_pci_get_bus (dev), grub_pci_get_device (dev), grub_pci_get_function (dev), pciid & 0xFFFF, pciid >> 16); - addr =3D grub_pci_make_address (dev, 2); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); class =3D grub_pci_read (addr); =20 /* Lookup the class name, if there isn't a specific one, @@ -155,14 +155,14 @@ =20 if (iospace) { - reg =3D 4; - while (reg < 10) + reg =3D GRUB_PCI_REG_ADDRESSES; + while (reg < GRUB_PCI_REG_CIS_POINTER) { grub_uint64_t space; addr =3D grub_pci_make_address (dev, reg); space =3D grub_pci_read (addr); =20 - reg++; + reg +=3D sizeof (grub_uint32_t); =20 if (space =3D=3D 0) continue; @@ -170,7 +170,9 @@ switch (space & GRUB_PCI_ADDR_SPACE_MASK) { case GRUB_PCI_ADDR_SPACE_IO: - grub_printf ("\tIO space %d at 0x%llx\n", (reg - 1) - 4, + grub_printf ("\tIO space %d at 0x%llx\n", + ((reg - GRUB_PCI_REG_ADDRESSES) + / sizeof (grub_uint32_t)) - 1, (unsigned long long) (space & GRUB_PCI_ADDR_IO_MASK)); break; @@ -180,9 +182,11 @@ { addr =3D grub_pci_make_address (dev, reg); space |=3D ((grub_uint64_t) grub_pci_read (addr)) << 32; - reg++; + reg +=3D sizeof (grub_uint32_t); grub_printf ("\t64-bit memory space %d at 0x%016llx [%s]\n", - (reg - 2) - 4, (unsigned long long) + ((reg - GRUB_PCI_REG_ADDRESSES) + / sizeof (grub_uint32_t)) - 2, + (unsigned long long) (space & GRUB_PCI_ADDR_MEM_MASK), space & GRUB_PCI_ADDR_MEM_PREFETCH ? "prefetchable" : "non-prefetchable"); @@ -190,7 +194,9 @@ } else grub_printf ("\t32-bit memory space %d at 0x%016llx [%s]\n", - (reg - 1) - 4, (unsigned long long)=20 + ((reg - GRUB_PCI_REG_ADDRESSES) + / sizeof (grub_uint32_t)) - 1, + (unsigned long long)=20 (space & GRUB_PCI_ADDR_MEM_MASK), space & GRUB_PCI_ADDR_MEM_PREFETCH ? "prefetchable" : "non-prefetchable"); =3D=3D=3D modified file 'disk/ata.c' --- disk/ata.c 2009-11-23 10:15:24 +0000 +++ disk/ata.c 2009-12-22 12:01:23 +0000 @@ -402,7 +402,7 @@ static int controller =3D 0; =20 /* Read class. */ - addr =3D grub_pci_make_address (dev, 2); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); class =3D grub_pci_read (addr); =20 /* Check if this class ID matches that of a PCI IDE Controller. */ @@ -429,9 +429,12 @@ { /* Read the BARs, which either contain a mmapped IO address or the IO port address. */ - addr =3D grub_pci_make_address (dev, 4 + 2 * i); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES + + sizeof (grub_uint64_t) * i); bar1 =3D grub_pci_read (addr); - addr =3D grub_pci_make_address (dev, 5 + 2 * i); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES + + sizeof (grub_uint64_t) * i + + sizeof (grub_uint32_t)); bar2 =3D grub_pci_read (addr); =20 /* Check if the BARs describe an IO region. */ =3D=3D=3D modified file 'include/grub/pci.h' --- include/grub/pci.h 2009-10-14 08:11:59 +0000 +++ include/grub/pci.h 2009-12-22 14:04:55 +0000 @@ -35,6 +35,37 @@ #define GRUB_PCI_ADDR_MEM_MASK ~0xf #define GRUB_PCI_ADDR_IO_MASK ~0x03 =20 +#define GRUB_PCI_REG_PCI_ID 0x00 +#define GRUB_PCI_REG_VENDOR 0x00 +#define GRUB_PCI_REG_DEVICE 0x02 +#define GRUB_PCI_REG_COMMAND 0x04 +#define GRUB_PCI_REG_STATUS 0x06 +#define GRUB_PCI_REG_REVISION 0x08 +#define GRUB_PCI_REG_CLASS 0x08 +#define GRUB_PCI_REG_CACHELINE 0x0c +#define GRUB_PCI_REG_LAT_TIMER 0x0d +#define GRUB_PCI_REG_HEADER_TYPE 0x0e +#define GRUB_PCI_REG_BIST 0x0f +#define GRUB_PCI_REG_ADDRESSES 0x10 + +/* Beware that 64-bit address takes 2 registers. */ +#define GRUB_PCI_REG_ADDRESS_REG0 0x10 +#define GRUB_PCI_REG_ADDRESS_REG1 0x14 +#define GRUB_PCI_REG_ADDRESS_REG2 0x18 +#define GRUB_PCI_REG_ADDRESS_REG3 0x1c +#define GRUB_PCI_REG_ADDRESS_REG4 0x20 +#define GRUB_PCI_REG_ADDRESS_REG5 0x24 + +#define GRUB_PCI_REG_CIS_POINTER 0x28 +#define GRUB_PCI_REG_SUBVENDOR 0x2c +#define GRUB_PCI_REG_SUBSYSTEM 0x2e +#define GRUB_PCI_REG_ROM_ADDRESS 0x30 +#define GRUB_PCI_REG_CAP_POINTER 0x34 +#define GRUB_PCI_REG_IRQ_LINE 0x3c +#define GRUB_PCI_REG_IRQ_PIN 0x3d +#define GRUB_PCI_REG_MIN_GNT 0x3e +#define GRUB_PCI_REG_MAX_LAT 0x3f + typedef grub_uint32_t grub_pci_id_t; =20 #ifdef GRUB_UTIL =3D=3D=3D modified file 'loader/i386/efi/linux.c' --- loader/i386/efi/linux.c 2009-11-30 18:09:11 +0000 +++ loader/i386/efi/linux.c 2009-12-22 12:01:48 +0000 @@ -477,7 +477,7 @@ { grub_pci_address_t addr; =20 - addr =3D grub_pci_make_address (dev, 2); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); if (grub_pci_read (addr) >> 24 =3D=3D 0x3) { int i; =3D=3D=3D modified file 'loader/i386/efi/xnu.c' --- loader/i386/efi/xnu.c 2009-11-30 18:09:11 +0000 +++ loader/i386/efi/xnu.c 2009-12-22 12:02:02 +0000 @@ -79,7 +79,7 @@ { grub_pci_address_t addr; =20 - addr =3D grub_pci_make_address (dev, 2); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); if (grub_pci_read (addr) >> 24 =3D=3D 0x3) { int i; =3D=3D=3D modified file 'util/pci.c' --- util/pci.c 2009-12-11 21:12:57 +0000 +++ util/pci.c 2009-12-22 12:02:33 +0000 @@ -26,7 +26,7 @@ { grub_pci_address_t ret; ret.dev =3D dev; - ret.pos =3D reg << 2; + ret.pos =3D reg; return ret; } =20 =3D=3D=3D modified file 'video/efi_uga.c' --- video/efi_uga.c 2009-11-30 18:09:11 +0000 +++ video/efi_uga.c 2009-12-22 12:02:17 +0000 @@ -92,7 +92,7 @@ { grub_pci_address_t addr; =20 - addr =3D grub_pci_make_address (dev, 2); + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); if (grub_pci_read (addr) >> 24 =3D=3D 0x3) { int i; --------------040005070201070809020105-- --------------enig5AD2551B5863670264197F79 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iF4EAREKAAYFAksw08EACgkQNak7dOguQgkDHwD/SjZK+qaY1Gx60r2QBPZKT6l9 7mq0/TmPPOj8G4GojeMA+wbGo0JqTnBGTL3a8Z41wRjB35BONTwzAPHJibfhrT2L =XQiy -----END PGP SIGNATURE----- --------------enig5AD2551B5863670264197F79--