This source file includes following definitions.
- acpitimermatch
- acpitimerattach
- acpi_get_timecount
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
31 int acpitimermatch(struct device *, void *, void *);
32 void acpitimerattach(struct device *, struct device *, void *);
33
34 #ifdef __HAVE_TIMECOUNTER
35 u_int acpi_get_timecount(struct timecounter *tc);
36
37 static struct timecounter acpi_timecounter = {
38 acpi_get_timecount,
39 0,
40 0x00ffffff,
41 ACPI_FREQUENCY,
42 0,
43 1000
44 };
45 #endif
46
47 struct acpitimer_softc {
48 struct device sc_dev;
49
50 bus_space_tag_t sc_iot;
51 bus_space_handle_t sc_ioh;
52 };
53
54 struct cfattach acpitimer_ca = {
55 sizeof(struct acpitimer_softc), acpitimermatch, acpitimerattach
56 };
57
58 struct cfdriver acpitimer_cd = {
59 NULL, "acpitimer", DV_DULL
60 };
61
62 int
63 acpitimermatch(struct device *parent, void *match, void *aux)
64 {
65 struct acpi_attach_args *aa = aux;
66 struct cfdata *cf = match;
67
68
69 if (aa->aaa_name == NULL ||
70 strcmp(aa->aaa_name, cf->cf_driver->cd_name) != 0 ||
71 aa->aaa_table != NULL)
72 return (0);
73
74 return (1);
75 }
76
77 void
78 acpitimerattach(struct device *parent, struct device *self, void *aux)
79 {
80 struct acpitimer_softc *sc = (struct acpitimer_softc *) self;
81 struct acpi_softc *psc = (struct acpi_softc *) parent;
82 int rc;
83
84 if (psc->sc_fadt->hdr_revision >= 3)
85 rc = acpi_map_address(psc, &psc->sc_fadt->x_pm_tmr_blk, 0,
86 psc->sc_fadt->pm_tmr_len, &sc->sc_ioh, &sc->sc_iot);
87 else
88 rc = acpi_map_address(psc, NULL, psc->sc_fadt->pm_tmr_blk,
89 psc->sc_fadt->pm_tmr_len, &sc->sc_ioh, &sc->sc_iot);
90 if (rc) {
91 printf(": can't map i/o space\n");
92 return;
93 }
94
95 printf(": %ld Hz, %d bits\n", ACPI_FREQUENCY,
96 psc->sc_fadt->flags & FADT_TMR_VAL_EXT ? 32 : 24);
97
98 #ifdef __HAVE_TIMECOUNTER
99 if (psc->sc_fadt->flags & FADT_TMR_VAL_EXT)
100 acpi_timecounter.tc_counter_mask = 0xffffffffU;
101 acpi_timecounter.tc_priv = sc;
102 acpi_timecounter.tc_name = sc->sc_dev.dv_xname;
103 tc_init(&acpi_timecounter);
104 #endif
105 }
106
107
108 #ifdef __HAVE_TIMECOUNTER
109 u_int
110 acpi_get_timecount(struct timecounter *tc)
111 {
112 struct acpitimer_softc *sc = tc->tc_priv;
113 u_int u1, u2, u3;
114
115 u2 = bus_space_read_4(sc->sc_iot, sc->sc_ioh, 0);
116 u3 = bus_space_read_4(sc->sc_iot, sc->sc_ioh, 0);
117 do {
118 u1 = u2;
119 u2 = u3;
120 u3 = bus_space_read_4(sc->sc_iot, sc->sc_ioh, 0);
121 } while (u1 > u2 || u2 > u3);
122
123 return (u2);
124 }
125 #endif