Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/libsaio/hpet.c

1/*
2 * Copyright (c) 2009 Evan Lojewski. All rights reserved.
3 */
4
5/*
6 * High Precision Event Timer (HPET)
7 */
8
9#include "libsaio.h"
10#include "pci.h"
11#include "hpet.h"
12
13#ifndef DEBUG_HPET
14#define DEBUG_HPET 0
15#endif
16
17#if DEBUG_HPET
18#define DBG(x...) printf(x)
19#else
20#define DBG(x...)
21#endif
22
23static struct lpc_controller_t lpc_controllers[] = {
24
25// Default unknown chipset
26{ 0, 0, "" },
27
28// Intel
29{ 0x8086, 0x24dc, "ICH5" },
30{ 0x8086, 0x2640, "ICH6" },
31{ 0x8086, 0x2641, "ICH6M" },
32
33{ 0x8086, 0x27b0, "ICH7 DH" },
34{ 0x8086, 0x27b8, "ICH7" },
35{ 0x8086, 0x27b9, "ICH7M" },
36{ 0x8086, 0x27bd, "ICH7M DH" },
37
38{ 0x8086, 0x2810, "ICH8R" },
39{ 0x8086, 0x2811, "ICH8M-E" },
40{ 0x8086, 0x2812, "ICH8DH" },
41{ 0x8086, 0x2814, "ICH8DO" },
42{ 0x8086, 0x2815, "ICH8M" },
43
44{ 0x8086, 0x2912, "ICH9DH" },
45{ 0x8086, 0x2914, "ICH9DO" },
46{ 0x8086, 0x2916, "ICH9R" },
47{ 0x8086, 0x2917, "ICH9M-E" },
48{ 0x8086, 0x2918, "ICH9" },
49{ 0x8086, 0x2919, "ICH9M" },
50
51{ 0x8086, 0x3a14, "ICH10DO" },
52{ 0x8086, 0x3a16, "ICH10R" },
53{ 0x8086, 0x3a18, "ICH10" },
54{ 0x8086, 0x3a1a, "ICH10D" },
55
56};
57
58void force_enable_hpet(pci_dt_t *lpc_dev)
59{
60int i;
61uint32_tval, hpet_address = 0xFED00000;
62void*rcba;
63
64/* LPC on Intel ICH is always (?) at 00:1f.0 */
65for(i = 1; i < sizeof(lpc_controllers) / sizeof(lpc_controllers[0]); i++)
66if ((lpc_controllers[i].vendor == lpc_dev->vendor_id)
67&& (lpc_controllers[i].device == lpc_dev->device_id))
68{
69rcba = (void *)(pci_config_read32(lpc_dev->dev.addr, 0xF0) & 0xFFFFC000);
70
71DBG("Intel(R) %s LPC Interface [%04x:%04x], MMIO @ 0x%lx\n",
72lpc_controllers[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba);
73
74if (rcba == 0)
75{
76printf(" RCBA disabled; cannot force enable HPET\n");
77}
78else
79{
80val = REG32(rcba, 0x3404);
81if (val & 0x80)
82{
83// HPET is enabled in HPTC. Just not reported by BIOS
84DBG(" HPET is enabled in HPTC, just not reported by BIOS\n");
85hpet_address |= (val & 3) << 12 ;
86DBG(" HPET MMIO @ 0x%lx\n", hpet_address);
87}
88else
89{
90// HPET disabled in HPTC. Trying to enable
91DBG(" HPET is disabled in HPTC, trying to enable\n");
92REG32(rcba, 0x3404) = val | 0x80;
93hpet_address |= (val & 3) << 12 ;
94DBG(" Force enabled HPET, MMIO @ 0x%lx\n", hpet_address);
95}
96
97// verify if the job is done
98val = REG32(rcba, 0x3404);
99if (!(val & 0x80))
100{
101printf(" Failed to force enable HPET\n");
102}
103}
104break;
105}
106
107#if DEBUG_HPET
108printf("Press [Enter] to continue...\n");
109getchar();
110#endif
111}
112

Archive Download this file

Revision: 2666