Re: [PATCH] hpet: Enable hidden HPET on NVidia motherboards

2007-04-15 Thread Alistair John Strachan
On Sunday 15 April 2007 21:14, Mikko Tiihonen wrote:
> Enables HPET for NVidia motherboards with broken BIOS. The patch reads the
> HPET address from the pci config space. The patch should also work if ACPI
> is disabled.
>
> The HPET search is done in early-quirks because even
> DECLARE_PCI_FIXUP_EARLY was too late. If the new quirk causes problems it
> can be disabled with the nohpet boot option.
>
> The patch assumes that the BIOS has done the basic setup of HPET, but has
> not published the result in ACPI tables. This is at least true for some
> Asus and Gigabyte motherboards.

This works fine on my DFI Lanparty UT nForce4 CK804 mainboard:

[EMAIL PROTECTED]:~$ dmesg | grep hpet
[   25.677099] hpet0: at MMIO 0xfefff000, IRQs 2, 8, 31
[   25.677102] hpet0: 3 32-bit timers, 2500 Hz
[   25.678799] Time: hpet clocksource has been installed.

I've been wanting hpets for a while, this patch is extremely useful to me.

Unfortunately your patch does not seem to apply with standard tools, perhaps 
your mailer corrupted it (I just hand applied it).

Thanks Mikko.

-- 
Cheers,
Alistair.

Final year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hpet: Enable hidden HPET on NVidia motherboards

2007-04-15 Thread Mikko Tiihonen


Enables HPET for NVidia motherboards with broken BIOS. The patch reads the 
HPET address from the pci config space. The patch should also work if ACPI is 
disabled.


The HPET search is done in early-quirks because even DECLARE_PCI_FIXUP_EARLY 
was too late. If the new quirk causes problems it can be disabled with the

nohpet boot option.

The patch assumes that the BIOS has done the basic setup of HPET, but has not 
published the result in ACPI tables. This is at least true for some Asus and 
Gigabyte motherboards.


Patch is against 2.6.21-rc6-git7 but should apply cleanly to most kernels.

Signed-off-by: Mikko Tiihonen <[EMAIL PROTECTED]>

---

It looks probable that most NVidia chipsets have the HPET address at 0x44. It 
might be possible to enable the HPET even if BIOS did not initialize it 
properly by writing the wanted address there. Some other pci config space bits 
might need to be fiddled around too, most likely candidates are 0x74 bit 2 and 
0xA3 bit ?. One or both of them have been identified to change in some 
motherboards when HPET is enabled/disabled in BIOS.


--- arch/x86_64/kernel/early-quirks.c.orig  2007-04-16 01:30:33.0 
+0300
+++ arch/x86_64/kernel/early-quirks.c   2007-04-16 01:27:23.0 +0300
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 

 static void __init via_bugs(void)
 {
@@ -36,6 +37,104 @@ static int __init nvidia_hpet_check(stru
 }
 #endif

+#ifdef CONFIG_HPET
+
+static u32 nvidia_hpet_chips[] __initdata = {
+   /* ISA Bridge */
+   PCI_VENDOR_ID_NVIDIA | (0x0050 << 16),
+   PCI_VENDOR_ID_NVIDIA | (0x0051 << 16),
+   /* LPC Bridge */
+   PCI_VENDOR_ID_NVIDIA | (0x0360 << 16),
+   PCI_VENDOR_ID_NVIDIA | (0x0361 << 16),
+   PCI_VENDOR_ID_NVIDIA | (0x0362 << 16),
+   PCI_VENDOR_ID_NVIDIA | (0x0363 << 16),
+   PCI_VENDOR_ID_NVIDIA | (0x0364 << 16),
+   PCI_VENDOR_ID_NVIDIA | (0x0365 << 16),
+   PCI_VENDOR_ID_NVIDIA | (0x0366 << 16),
+   PCI_VENDOR_ID_NVIDIA | (0x0367 << 16),
+   0,
+};
+
+static int __init force_enable_nvidia_hpet(void)
+{
+   int num, slot, func;
+   u32 addr;
+   struct resource *hpet_res;
+
+   if (hpet_address || nohpet)
+   return 0;
+
+   /* Poor man's PCI discovery */
+   for (num = 0; num < 32; num++) {
+   for (slot = 0; slot < 32; slot++) {
+   for (func = 0; func < 8; func++) {
+   u32 class;
+   u32 vendor;
+   u8 type;
+   int i;
+   class = read_pci_config(num,slot,func,
+   PCI_CLASS_REVISION);
+   if (class == 0x)
+   break;
+   vendor = read_pci_config(num, slot, func,
+PCI_VENDOR_ID);
+
+   for (i = 0; nvidia_hpet_chips[i]; i++)
+   if (nvidia_hpet_chips[i] == vendor) {
+   goto found;
+   }
+
+   type = read_pci_config_byte(num, slot, func,
+   PCI_HEADER_TYPE);
+   if (!(type & 0x80))
+   break;
+   }
+   }
+   }
+   return 0;
+
+ found:
+   addr = read_pci_config(num, slot, func, 0x44);
+   if (!addr) {
+   return 0;
+   }
+
+#define HPET_RESOURCE_NAME_SIZE 12
+   hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
+   if (!hpet_res) {
+   /* We could try writing to the 0x44 and see if that is enough
+* to enable HPET even if BIOS did not initialize it.
+*/
+   printk(KERN_INFO "HPET not set up by BIOS.\n");
+   return 0;
+   }
+
+   memset(hpet_res, 0, sizeof(*hpet_res));
+   hpet_res->name = (void *)_res[1];
+   hpet_res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+	strncpy((char *)hpet_res->name, "NVidia HPET", 
+		HPET_RESOURCE_NAME_SIZE);

+   hpet_res->start = addr;
+   hpet_res->end = hpet_res->start + HPET_MMAP_SIZE - 1;
+
+   if (request_resource(_resource, hpet_res)) {
+   printk(KERN_INFO "NVidia quirk failed. Could not "
+  "reserve resources for HPET at base: %#x\n", addr);
+   return 0;
+   }
+
+   hpet_address = addr;
+   printk(KERN_INFO "NVidia quirk. Enabled hidden HPET that BIOS had "
+  "configured at base: %#x\n", addr);
+   return 1;
+}
+#else
+static int __init force_enable_nvidia_hpet(void)
+{
+   return 0;
+}
+#endif
+
 static void __init nvidia_bugs(void)
 {
 #ifdef CONFIG_ACPI

[PATCH] hpet: Enable hidden HPET on NVidia motherboards

2007-04-15 Thread Mikko Tiihonen


Enables HPET for NVidia motherboards with broken BIOS. The patch reads the 
HPET address from the pci config space. The patch should also work if ACPI is 
disabled.


The HPET search is done in early-quirks because even DECLARE_PCI_FIXUP_EARLY 
was too late. If the new quirk causes problems it can be disabled with the

nohpet boot option.

The patch assumes that the BIOS has done the basic setup of HPET, but has not 
published the result in ACPI tables. This is at least true for some Asus and 
Gigabyte motherboards.


Patch is against 2.6.21-rc6-git7 but should apply cleanly to most kernels.

Signed-off-by: Mikko Tiihonen [EMAIL PROTECTED]

---

It looks probable that most NVidia chipsets have the HPET address at 0x44. It 
might be possible to enable the HPET even if BIOS did not initialize it 
properly by writing the wanted address there. Some other pci config space bits 
might need to be fiddled around too, most likely candidates are 0x74 bit 2 and 
0xA3 bit ?. One or both of them have been identified to change in some 
motherboards when HPET is enabled/disabled in BIOS.


--- arch/x86_64/kernel/early-quirks.c.orig  2007-04-16 01:30:33.0 
+0300
+++ arch/x86_64/kernel/early-quirks.c   2007-04-16 01:27:23.0 +0300
@@ -15,6 +15,7 @@
 #include asm/pci-direct.h
 #include asm/proto.h
 #include asm/dma.h
+#include linux/bootmem.h

 static void __init via_bugs(void)
 {
@@ -36,6 +37,104 @@ static int __init nvidia_hpet_check(stru
 }
 #endif

+#ifdef CONFIG_HPET
+
+static u32 nvidia_hpet_chips[] __initdata = {
+   /* ISA Bridge */
+   PCI_VENDOR_ID_NVIDIA | (0x0050  16),
+   PCI_VENDOR_ID_NVIDIA | (0x0051  16),
+   /* LPC Bridge */
+   PCI_VENDOR_ID_NVIDIA | (0x0360  16),
+   PCI_VENDOR_ID_NVIDIA | (0x0361  16),
+   PCI_VENDOR_ID_NVIDIA | (0x0362  16),
+   PCI_VENDOR_ID_NVIDIA | (0x0363  16),
+   PCI_VENDOR_ID_NVIDIA | (0x0364  16),
+   PCI_VENDOR_ID_NVIDIA | (0x0365  16),
+   PCI_VENDOR_ID_NVIDIA | (0x0366  16),
+   PCI_VENDOR_ID_NVIDIA | (0x0367  16),
+   0,
+};
+
+static int __init force_enable_nvidia_hpet(void)
+{
+   int num, slot, func;
+   u32 addr;
+   struct resource *hpet_res;
+
+   if (hpet_address || nohpet)
+   return 0;
+
+   /* Poor man's PCI discovery */
+   for (num = 0; num  32; num++) {
+   for (slot = 0; slot  32; slot++) {
+   for (func = 0; func  8; func++) {
+   u32 class;
+   u32 vendor;
+   u8 type;
+   int i;
+   class = read_pci_config(num,slot,func,
+   PCI_CLASS_REVISION);
+   if (class == 0x)
+   break;
+   vendor = read_pci_config(num, slot, func,
+PCI_VENDOR_ID);
+
+   for (i = 0; nvidia_hpet_chips[i]; i++)
+   if (nvidia_hpet_chips[i] == vendor) {
+   goto found;
+   }
+
+   type = read_pci_config_byte(num, slot, func,
+   PCI_HEADER_TYPE);
+   if (!(type  0x80))
+   break;
+   }
+   }
+   }
+   return 0;
+
+ found:
+   addr = read_pci_config(num, slot, func, 0x44);
+   if (!addr) {
+   return 0;
+   }
+
+#define HPET_RESOURCE_NAME_SIZE 12
+   hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
+   if (!hpet_res) {
+   /* We could try writing to the 0x44 and see if that is enough
+* to enable HPET even if BIOS did not initialize it.
+*/
+   printk(KERN_INFO HPET not set up by BIOS.\n);
+   return 0;
+   }
+
+   memset(hpet_res, 0, sizeof(*hpet_res));
+   hpet_res-name = (void *)hpet_res[1];
+   hpet_res-flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+	strncpy((char *)hpet_res-name, NVidia HPET, 
+		HPET_RESOURCE_NAME_SIZE);

+   hpet_res-start = addr;
+   hpet_res-end = hpet_res-start + HPET_MMAP_SIZE - 1;
+
+   if (request_resource(iomem_resource, hpet_res)) {
+   printk(KERN_INFO NVidia quirk failed. Could not 
+  reserve resources for HPET at base: %#x\n, addr);
+   return 0;
+   }
+
+   hpet_address = addr;
+   printk(KERN_INFO NVidia quirk. Enabled hidden HPET that BIOS had 
+  configured at base: %#x\n, addr);
+   return 1;
+}
+#else
+static int __init force_enable_nvidia_hpet(void)
+{
+   return 0;
+}
+#endif
+
 static void __init nvidia_bugs(void)
 {
 

Re: [PATCH] hpet: Enable hidden HPET on NVidia motherboards

2007-04-15 Thread Alistair John Strachan
On Sunday 15 April 2007 21:14, Mikko Tiihonen wrote:
 Enables HPET for NVidia motherboards with broken BIOS. The patch reads the
 HPET address from the pci config space. The patch should also work if ACPI
 is disabled.

 The HPET search is done in early-quirks because even
 DECLARE_PCI_FIXUP_EARLY was too late. If the new quirk causes problems it
 can be disabled with the nohpet boot option.

 The patch assumes that the BIOS has done the basic setup of HPET, but has
 not published the result in ACPI tables. This is at least true for some
 Asus and Gigabyte motherboards.

This works fine on my DFI Lanparty UT nForce4 CK804 mainboard:

[EMAIL PROTECTED]:~$ dmesg | grep hpet
[   25.677099] hpet0: at MMIO 0xfefff000, IRQs 2, 8, 31
[   25.677102] hpet0: 3 32-bit timers, 2500 Hz
[   25.678799] Time: hpet clocksource has been installed.

I've been wanting hpets for a while, this patch is extremely useful to me.

Unfortunately your patch does not seem to apply with standard tools, perhaps 
your mailer corrupted it (I just hand applied it).

Thanks Mikko.

-- 
Cheers,
Alistair.

Final year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/