acpi_timer.c (80442) | acpi_timer.c (80602) |
---|---|
1/*- 2 * Copyright (c) 2000, 2001 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * | 1/*- 2 * Copyright (c) 2000, 2001 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/sys/dev/acpica/acpi_timer.c 80442 2001-07-27 09:01:13Z msmith $ | 27 * $FreeBSD: head/sys/dev/acpica/acpi_timer.c 80602 2001-07-30 08:57:55Z msmith $ |
28 */ | 28 */ |
29/* 30 * ---------------------------------------------------------------------------- 31 * "THE BEER-WARE LICENSE" (Revision 42): 32 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 33 * can do whatever you want with this stuff. If we meet some day, and you think 34 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 35 * ---------------------------------------------------------------------------- 36 */ | |
37#include "opt_acpi.h" 38#include <sys/param.h> 39#include <sys/bus.h> 40#include <sys/kernel.h> 41#include <sys/sysctl.h> 42#include <sys/timetc.h> 43 44#include <machine/bus_pio.h> --- 18 unchanged lines hidden (view full) --- 63#define _COMPONENT ACPI_SYSTEM 64MODULE_NAME("TIMER") 65 66static device_t acpi_timer_dev; 67struct resource *acpi_timer_reg; 68#define TIMER_READ bus_space_read_4(rman_get_bustag(acpi_timer_reg), \ 69 rman_get_bushandle(acpi_timer_reg), \ 70 0) | 29#include "opt_acpi.h" 30#include <sys/param.h> 31#include <sys/bus.h> 32#include <sys/kernel.h> 33#include <sys/sysctl.h> 34#include <sys/timetc.h> 35 36#include <machine/bus_pio.h> --- 18 unchanged lines hidden (view full) --- 55#define _COMPONENT ACPI_SYSTEM 56MODULE_NAME("TIMER") 57 58static device_t acpi_timer_dev; 59struct resource *acpi_timer_reg; 60#define TIMER_READ bus_space_read_4(rman_get_bustag(acpi_timer_reg), \ 61 rman_get_bushandle(acpi_timer_reg), \ 62 0) |
71static int acpi_timer_flags; 72/* 73 * ] 20. ACPI Timer Errata 74 * ] 75 * ] Problem: The power management timer may return improper result when 76 * ] read. Although the timer value settles properly after incrementing, 77 * ] while incrementing there is a 3nS window every 69.8nS where the 78 * ] timer value is indeterminate (a 4.2% chance that the data will be 79 * ] incorrect when read). As a result, the ACPI free running count up 80 * ] timer specification is violated due to erroneous reads. Implication: 81 * ] System hangs due to the "inaccuracy" of the timer when used by 82 * ] software for time critical events and delays. 83 * ] 84 * ] Workaround: Read the register twice and compare. 85 * ] Status: This will not be fixed in the PIIX4 or PIIX4E, it is fixed 86 * ] in the PIIX4M. 87 * 88 * The counter is in other words not latched to the PCI bus clock when 89 * read. Notice the workaround isn't: We need to read until we have 90 * three monotonic samples and then use the middle one, otherwise we are 91 * not protected against the fact that the bits can be wrong in two 92 * directions. If we only cared about monosity two reads would be enough. 93 */ 94#define TFLAG_NEED_PIIX_WAR (1 << 0) | |
95 96static u_int acpi_timer_frequency = 14318182/4; 97 98static void acpi_timer_identify(driver_t *driver, device_t parent); 99static int acpi_timer_probe(device_t dev); 100static int acpi_timer_attach(device_t dev); | 63 64static u_int acpi_timer_frequency = 14318182/4; 65 66static void acpi_timer_identify(driver_t *driver, device_t parent); 67static int acpi_timer_probe(device_t dev); 68static int acpi_timer_attach(device_t dev); |
101static int acpi_timer_pci_probe(device_t dev); | |
102static unsigned acpi_timer_get_timecount(struct timecounter *tc); 103static int acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS); 104static void acpi_timer_test(void); 105 106/* 107 * Driver hung off ACPI. 108 */ 109static device_method_t acpi_timer_methods[] = { --- 9 unchanged lines hidden (view full) --- 119 acpi_timer_methods, 120 0, 121}; 122 123devclass_t acpi_timer_devclass; 124DRIVER_MODULE(acpi_timer, acpi, acpi_timer_driver, acpi_timer_devclass, 0, 0); 125 126/* | 69static unsigned acpi_timer_get_timecount(struct timecounter *tc); 70static int acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS); 71static void acpi_timer_test(void); 72 73/* 74 * Driver hung off ACPI. 75 */ 76static device_method_t acpi_timer_methods[] = { --- 9 unchanged lines hidden (view full) --- 86 acpi_timer_methods, 87 0, 88}; 89 90devclass_t acpi_timer_devclass; 91DRIVER_MODULE(acpi_timer, acpi, acpi_timer_driver, acpi_timer_devclass, 0, 0); 92 93/* |
127 * Chipset workaround driver hung off PCI. 128 */ 129static device_method_t acpi_timer_pci_methods[] = { 130 DEVMETHOD(device_probe, acpi_timer_pci_probe), 131 {0, 0} 132}; 133 134static driver_t acpi_timer_pci_driver = { 135 "acpi_timer_pci", 136 acpi_timer_pci_methods, 137 0, 138}; 139 140devclass_t acpi_timer_pci_devclass; 141DRIVER_MODULE(acpi_timer_pci, pci, acpi_timer_pci_driver, acpi_timer_pci_devclass, 0, 0); 142 143/* | |
144 * Timecounter. 145 */ 146static struct timecounter acpi_timer_timecounter = { 147 acpi_timer_get_timecount, 148 0, 149 0xffffff, 150 0, 151 "ACPI" --- 30 unchanged lines hidden (view full) --- 182 bus_set_resource(dev, SYS_RES_IOPORT, rid, AcpiGbl_FADT->V1_PmTmrBlk, sizeof(u_int32_t)); 183 if ((acpi_timer_reg = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE)) == NULL) { 184 device_printf(dev, "couldn't allocate I/O resource (port 0x%x)\n", AcpiGbl_FADT->V1_PmTmrBlk); 185 return_VOID; 186 } 187 if (getenv("debug.acpi.timer_test") != NULL) 188 acpi_timer_test(); 189 | 94 * Timecounter. 95 */ 96static struct timecounter acpi_timer_timecounter = { 97 acpi_timer_get_timecount, 98 0, 99 0xffffff, 100 0, 101 "ACPI" --- 30 unchanged lines hidden (view full) --- 132 bus_set_resource(dev, SYS_RES_IOPORT, rid, AcpiGbl_FADT->V1_PmTmrBlk, sizeof(u_int32_t)); 133 if ((acpi_timer_reg = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE)) == NULL) { 134 device_printf(dev, "couldn't allocate I/O resource (port 0x%x)\n", AcpiGbl_FADT->V1_PmTmrBlk); 135 return_VOID; 136 } 137 if (getenv("debug.acpi.timer_test") != NULL) 138 acpi_timer_test(); 139 |
140 acpi_timer_timecounter.tc_get_timecount = acpi_timer_get_timecount; |
|
190 acpi_timer_timecounter.tc_frequency = acpi_timer_frequency; 191 tc_init(&acpi_timer_timecounter); 192 193 sprintf(desc, "%d-bit timer at 3.579545MHz", AcpiGbl_FADT->TmrValExt ? 32 : 24); 194 device_set_desc_copy(dev, desc); 195 196 return_VOID; 197} --- 8 unchanged lines hidden (view full) --- 206 207static int 208acpi_timer_attach(device_t dev) 209{ 210 return(0); 211} 212 213/* | 141 acpi_timer_timecounter.tc_frequency = acpi_timer_frequency; 142 tc_init(&acpi_timer_timecounter); 143 144 sprintf(desc, "%d-bit timer at 3.579545MHz", AcpiGbl_FADT->TmrValExt ? 32 : 24); 145 device_set_desc_copy(dev, desc); 146 147 return_VOID; 148} --- 8 unchanged lines hidden (view full) --- 157 158static int 159acpi_timer_attach(device_t dev) 160{ 161 return(0); 162} 163 164/* |
214 * Look at PCI devices as they go past, and if we detect a PIIX4 older than 215 * the PIIX4M, set the PIIX_WAR flag. 216 * 217 * XXX do we know that other timecounters work? Interesting question. 218 */ 219static int 220acpi_timer_pci_probe(device_t dev) 221{ 222 if ((pci_get_vendor(dev) == 0x8086) && 223 (pci_get_device(dev) == 0x7113) && 224 (pci_get_revid(dev) < 0x03)) { 225 acpi_timer_flags |= TFLAG_NEED_PIIX_WAR; 226 device_printf(acpi_timer_dev, "enabling PIIX4 timer workaround\n"); 227 } 228 229 return(ENXIO); /* we never match anything */ 230} 231 232/* | |
233 * Fetch current time value from hardware. | 165 * Fetch current time value from hardware. |
234 * 235 * XXX This is currently written to be "correct", not 236 * "fast". Optimisation is strongly indicated. | |
237 */ 238static unsigned 239acpi_timer_get_timecount(struct timecounter *tc) 240{ | 166 */ 167static unsigned 168acpi_timer_get_timecount(struct timecounter *tc) 169{ |
241 unsigned u1, u2, u3; 242 243 if (acpi_timer_flags & TFLAG_NEED_PIIX_WAR) { 244 u2 = TIMER_READ; 245 u3 = TIMER_READ; 246 do { 247 u1 = u2; 248 u2 = u3; 249 u3 = TIMER_READ; 250 } while (u1 > u2 || u2 > u3); 251 return (u2); 252 } else { 253 return(TIMER_READ); 254 } | 170 return(TIMER_READ); |
255} 256 257/* 258 * Timecounter freqency adjustment interface. 259 */ 260static int 261acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS) 262{ --- 40 unchanged lines hidden (view full) --- 303 u1, u2, u3); 304 } 305 u1 = u2; 306 u2 = u3; 307 u3 = TIMER_READ; 308 } 309} 310 | 171} 172 173/* 174 * Timecounter freqency adjustment interface. 175 */ 176static int 177acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS) 178{ --- 40 unchanged lines hidden (view full) --- 219 u1, u2, u3); 220 } 221 u1 = u2; 222 u2 = u3; 223 u3 = TIMER_READ; 224 } 225} 226 |
227/* 228 * Chipset workaround driver hung off PCI. 229 * 230 * ] 20. ACPI Timer Errata 231 * ] 232 * ] Problem: The power management timer may return improper result when 233 * ] read. Although the timer value settles properly after incrementing, 234 * ] while incrementing there is a 3nS window every 69.8nS where the 235 * ] timer value is indeterminate (a 4.2% chance that the data will be 236 * ] incorrect when read). As a result, the ACPI free running count up 237 * ] timer specification is violated due to erroneous reads. Implication: 238 * ] System hangs due to the "inaccuracy" of the timer when used by 239 * ] software for time critical events and delays. 240 * ] 241 * ] Workaround: Read the register twice and compare. 242 * ] Status: This will not be fixed in the PIIX4 or PIIX4E, it is fixed 243 * ] in the PIIX4M. 244 * 245 * The counter is in other words not latched to the PCI bus clock when 246 * read. Notice the workaround isn't: We need to read until we have 247 * three monotonic samples and then use the middle one, otherwise we are 248 * not protected against the fact that the bits can be wrong in two 249 * directions. If we only cared about monosity two reads would be enough. 250 */ 251 252static int acpi_timer_pci_probe(device_t dev); 253static unsigned acpi_timer_get_timecount_piix(struct timecounter *tc); 254 255static device_method_t acpi_timer_pci_methods[] = { 256 DEVMETHOD(device_probe, acpi_timer_pci_probe), 257 {0, 0} 258}; 259 260static driver_t acpi_timer_pci_driver = { 261 "acpi_timer_pci", 262 acpi_timer_pci_methods, 263 0, 264}; 265 266devclass_t acpi_timer_pci_devclass; 267DRIVER_MODULE(acpi_timer_pci, pci, acpi_timer_pci_driver, acpi_timer_pci_devclass, 0, 0); 268 269/* 270 * Look at PCI devices as they go past, and if we detect a PIIX4 older than 271 * the PIIX4M, use an alternate get_timecount routine. 272 * 273 * XXX do we know that other timecounters work? Perhaps we should test them? 274 */ 275static int 276acpi_timer_pci_probe(device_t dev) 277{ 278 if ((pci_get_vendor(dev) == 0x8086) && 279 (pci_get_device(dev) == 0x7113) && 280 (pci_get_revid(dev) < 0x03)) { 281 acpi_timer_timecounter.tc_get_timecount = acpi_timer_get_timecount_piix; 282 acpi_timer_timecounter.tc_name = "ACPI-PIIX"; 283 device_printf(acpi_timer_dev, "enabling PIIX4 timer workaround\n"); 284 } 285 286 return(ENXIO); /* we never match anything */ 287} 288 289/* 290 * Read the buggy PIIX4 ACPI timer and compensate for its behaviour. 291 */ 292static unsigned 293acpi_timer_get_timecount_piix(struct timecounter *tc) 294{ 295 unsigned u1, u2, u3; 296 297 u2 = TIMER_READ; 298 u3 = TIMER_READ; 299 do { 300 u1 = u2; 301 u2 = u3; 302 u3 = TIMER_READ; 303 } while (u1 > u2 || u2 > u3); 304 return (u2); 305} 306 |
|