This source file includes following definitions.
- acpihpet_match
- acpihpet_attach
- acpihpet_gettime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #include <sys/device.h>
21 #include <sys/malloc.h>
22 #ifdef __HAVE_TIMECOUNTER
23 #include <sys/timetc.h>
24 #endif
25
26 #include <machine/bus.h>
27
28 #include <dev/acpi/acpireg.h>
29 #include <dev/acpi/acpivar.h>
30 #include <dev/acpi/acpidev.h>
31
32 int acpihpet_match(struct device *, void *, void *);
33 void acpihpet_attach(struct device *, struct device *, void *);
34
35 #ifdef __HAVE_TIMECOUNTER
36 u_int acpihpet_gettime(struct timecounter *tc);
37
38 static struct timecounter hpet_timecounter = {
39 acpihpet_gettime,
40 0,
41 0xffffffff,
42 0,
43 0,
44 1000
45 };
46 #endif
47
48 struct acpihpet_softc {
49 struct device sc_dev;
50
51 bus_space_tag_t sc_iot;
52 bus_space_handle_t sc_ioh;
53 };
54
55 struct cfattach acpihpet_ca = {
56 sizeof(struct acpihpet_softc), acpihpet_match, acpihpet_attach
57 };
58
59 struct cfdriver acpihpet_cd = {
60 NULL, "acpihpet", DV_DULL
61 };
62
63 int
64 acpihpet_match(struct device *parent, void *match, void *aux)
65 {
66 struct acpi_attach_args *aaa = aux;
67 struct acpi_table_header *hdr;
68
69
70
71
72 if (aaa->aaa_table == NULL)
73 return (0);
74
75
76
77
78 hdr = (struct acpi_table_header *)aaa->aaa_table;
79 if (memcmp(hdr->signature, HPET_SIG, sizeof(HPET_SIG) - 1) != 0)
80 return (0);
81
82 return (1);
83 }
84
85 void
86 acpihpet_attach(struct device *parent, struct device *self, void *aux)
87 {
88 struct acpihpet_softc *sc = (struct acpihpet_softc *) self;
89 struct acpi_softc *psc = (struct acpi_softc *)parent;
90 struct acpi_attach_args *aaa = aux;
91 struct acpi_hpet *hpet = (struct acpi_hpet *)aaa->aaa_table;
92 u_int64_t period, freq;
93
94 if (acpi_map_address(psc, &hpet->base_address, 0, HPET_REG_SIZE,
95 &sc->sc_ioh, &sc->sc_iot)) {
96 printf(": can't map i/o space\n");
97 return;
98 }
99
100 period = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
101 HPET_CAPABILITIES + sizeof(u_int32_t));
102 freq = 1000000000000000ull / period;
103 printf(": %lld Hz\n", freq);
104
105 #ifdef __HAVE_TIMECOUNTER
106 hpet_timecounter.tc_frequency = (u_int32_t)freq;
107 hpet_timecounter.tc_priv = sc;
108 hpet_timecounter.tc_name = sc->sc_dev.dv_xname;
109 bus_space_write_4(sc->sc_iot, sc->sc_ioh, HPET_CONFIGURATION, 1);
110 tc_init(&hpet_timecounter);
111 #endif
112 }
113
114 #ifdef __HAVE_TIMECOUNTER
115 u_int
116 acpihpet_gettime(struct timecounter *tc)
117 {
118 struct acpihpet_softc *sc = tc->tc_priv;
119
120 return (bus_space_read_4(sc->sc_iot, sc->sc_ioh, HPET_MAIN_COUNTER));
121 }
122 #endif