acpi_machdep.c revision 197536
1/*- 2 * Copyright (c) 2001 Mitsuru IWASAKI 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD: head/sys/amd64/acpica/acpi_machdep.c 197536 2009-09-27 14:00:16Z jkim $"); 29 30#include <sys/param.h> 31#include <sys/bus.h> 32#include <sys/kernel.h> 33#include <sys/module.h> 34#include <sys/sysctl.h> 35#include <vm/vm.h> 36#include <vm/pmap.h> 37 38#include <contrib/dev/acpica/include/acpi.h> 39#include <contrib/dev/acpica/include/accommon.h> 40#include <contrib/dev/acpica/include/actables.h> 41 42#include <dev/acpica/acpivar.h> 43 44#include <machine/nexusvar.h> 45 46/* 47 * APM driver emulation 48 */ 49 50#include <sys/condvar.h> 51#include <sys/conf.h> 52#include <sys/fcntl.h> 53#include <sys/malloc.h> 54#include <sys/poll.h> 55#include <sys/uio.h> 56 57#include <dev/acpica/acpiio.h> 58 59#include <machine/apm_bios.h> 60#include <i386/include/pc/bios.h> 61 62#include <i386/bios/apm.h> 63 64SYSCTL_DECL(_debug_acpi); 65 66int acpi_resume_beep; 67TUNABLE_INT("debug.acpi.resume_beep", &acpi_resume_beep); 68SYSCTL_INT(_debug_acpi, OID_AUTO, resume_beep, CTLFLAG_RW, &acpi_resume_beep, 69 0, "Beep the PC speaker when resuming"); 70 71int acpi_reset_video; 72TUNABLE_INT("hw.acpi.reset_video", &acpi_reset_video); 73 74static int intr_model = ACPI_INTR_PIC; 75static int apm_active; 76static struct clonedevs *apm_clones; 77 78MALLOC_DEFINE(M_APMDEV, "apmdev", "APM device emulation"); 79 80static d_open_t apmopen; 81static d_close_t apmclose; 82static d_write_t apmwrite; 83static d_ioctl_t apmioctl; 84static d_poll_t apmpoll; 85static d_kqfilter_t apmkqfilter; 86static void apmreadfiltdetach(struct knote *kn); 87static int apmreadfilt(struct knote *kn, long hint); 88static struct filterops apm_readfiltops = { 89 .f_isfd = 1, 90 .f_detach = apmreadfiltdetach, 91 .f_event = apmreadfilt, 92}; 93 94static struct cdevsw apm_cdevsw = { 95 .d_version = D_VERSION, 96 .d_flags = D_TRACKCLOSE | D_NEEDMINOR, 97 .d_open = apmopen, 98 .d_close = apmclose, 99 .d_write = apmwrite, 100 .d_ioctl = apmioctl, 101 .d_poll = apmpoll, 102 .d_name = "apm", 103 .d_kqfilter = apmkqfilter 104}; 105 106static int 107acpi_capm_convert_battstate(struct acpi_battinfo *battp) 108{ 109 int state; 110 111 state = APM_UNKNOWN; 112 113 if (battp->state & ACPI_BATT_STAT_DISCHARG) { 114 if (battp->cap >= 50) 115 state = 0; /* high */ 116 else 117 state = 1; /* low */ 118 } 119 if (battp->state & ACPI_BATT_STAT_CRITICAL) 120 state = 2; /* critical */ 121 if (battp->state & ACPI_BATT_STAT_CHARGING) 122 state = 3; /* charging */ 123 124 /* If still unknown, determine it based on the battery capacity. */ 125 if (state == APM_UNKNOWN) { 126 if (battp->cap >= 50) 127 state = 0; /* high */ 128 else 129 state = 1; /* low */ 130 } 131 132 return (state); 133} 134 135static int 136acpi_capm_convert_battflags(struct acpi_battinfo *battp) 137{ 138 int flags; 139 140 flags = 0; 141 142 if (battp->cap >= 50) 143 flags |= APM_BATT_HIGH; 144 else { 145 if (battp->state & ACPI_BATT_STAT_CRITICAL) 146 flags |= APM_BATT_CRITICAL; 147 else 148 flags |= APM_BATT_LOW; 149 } 150 if (battp->state & ACPI_BATT_STAT_CHARGING) 151 flags |= APM_BATT_CHARGING; 152 if (battp->state == ACPI_BATT_STAT_NOT_PRESENT) 153 flags = APM_BATT_NOT_PRESENT; 154 155 return (flags); 156} 157 158static int 159acpi_capm_get_info(apm_info_t aip) 160{ 161 int acline; 162 struct acpi_battinfo batt; 163 164 aip->ai_infoversion = 1; 165 aip->ai_major = 1; 166 aip->ai_minor = 2; 167 aip->ai_status = apm_active; 168 aip->ai_capabilities= 0xff00; /* unknown */ 169 170 if (acpi_acad_get_acline(&acline)) 171 aip->ai_acline = APM_UNKNOWN; /* unknown */ 172 else 173 aip->ai_acline = acline; /* on/off */ 174 175 if (acpi_battery_get_battinfo(NULL, &batt) != 0) { 176 aip->ai_batt_stat = APM_UNKNOWN; 177 aip->ai_batt_life = APM_UNKNOWN; 178 aip->ai_batt_time = -1; /* unknown */ 179 aip->ai_batteries = ~0U; /* unknown */ 180 } else { 181 aip->ai_batt_stat = acpi_capm_convert_battstate(&batt); 182 aip->ai_batt_life = batt.cap; 183 aip->ai_batt_time = (batt.min == -1) ? -1 : batt.min * 60; 184 aip->ai_batteries = acpi_battery_get_units(); 185 } 186 187 return (0); 188} 189 190static int 191acpi_capm_get_pwstatus(apm_pwstatus_t app) 192{ 193 device_t dev; 194 int acline, unit, error; 195 struct acpi_battinfo batt; 196 197 if (app->ap_device != PMDV_ALLDEV && 198 (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL)) 199 return (1); 200 201 if (app->ap_device == PMDV_ALLDEV) 202 error = acpi_battery_get_battinfo(NULL, &batt); 203 else { 204 unit = app->ap_device - PMDV_BATT0; 205 dev = devclass_get_device(devclass_find("battery"), unit); 206 if (dev != NULL) 207 error = acpi_battery_get_battinfo(dev, &batt); 208 else 209 error = ENXIO; 210 } 211 if (error) 212 return (1); 213 214 app->ap_batt_stat = acpi_capm_convert_battstate(&batt); 215 app->ap_batt_flag = acpi_capm_convert_battflags(&batt); 216 app->ap_batt_life = batt.cap; 217 app->ap_batt_time = (batt.min == -1) ? -1 : batt.min * 60; 218 219 if (acpi_acad_get_acline(&acline)) 220 app->ap_acline = APM_UNKNOWN; 221 else 222 app->ap_acline = acline; /* on/off */ 223 224 return (0); 225} 226 227/* Create single-use devices for /dev/apm and /dev/apmctl. */ 228static void 229apm_clone(void *arg, struct ucred *cred, char *name, int namelen, 230 struct cdev **dev) 231{ 232 int ctl_dev, unit; 233 234 if (*dev != NULL) 235 return; 236 if (strcmp(name, "apmctl") == 0) 237 ctl_dev = TRUE; 238 else if (strcmp(name, "apm") == 0) 239 ctl_dev = FALSE; 240 else 241 return; 242 243 /* Always create a new device and unit number. */ 244 unit = -1; 245 if (clone_create(&apm_clones, &apm_cdevsw, &unit, dev, 0)) { 246 if (ctl_dev) { 247 *dev = make_dev(&apm_cdevsw, unit, 248 UID_ROOT, GID_OPERATOR, 0660, "apmctl%d", unit); 249 } else { 250 *dev = make_dev(&apm_cdevsw, unit, 251 UID_ROOT, GID_OPERATOR, 0664, "apm%d", unit); 252 } 253 if (*dev != NULL) { 254 dev_ref(*dev); 255 (*dev)->si_flags |= SI_CHEAPCLONE; 256 } 257 } 258} 259 260/* Create a struct for tracking per-device suspend notification. */ 261static struct apm_clone_data * 262apm_create_clone(struct cdev *dev, struct acpi_softc *acpi_sc) 263{ 264 struct apm_clone_data *clone; 265 266 clone = malloc(sizeof(*clone), M_APMDEV, M_WAITOK); 267 clone->cdev = dev; 268 clone->acpi_sc = acpi_sc; 269 clone->notify_status = APM_EV_NONE; 270 bzero(&clone->sel_read, sizeof(clone->sel_read)); 271 knlist_init_mtx(&clone->sel_read.si_note, &acpi_mutex); 272 273 /* 274 * The acpi device is always managed by devd(8) and is considered 275 * writable (i.e., ack is required to allow suspend to proceed.) 276 */ 277 if (strcmp("acpi", devtoname(dev)) == 0) 278 clone->flags = ACPI_EVF_DEVD | ACPI_EVF_WRITE; 279 else 280 clone->flags = ACPI_EVF_NONE; 281 282 ACPI_LOCK(acpi); 283 STAILQ_INSERT_TAIL(&acpi_sc->apm_cdevs, clone, entries); 284 ACPI_UNLOCK(acpi); 285 return (clone); 286} 287 288static int 289apmopen(struct cdev *dev, int flag, int fmt, struct thread *td) 290{ 291 struct acpi_softc *acpi_sc; 292 struct apm_clone_data *clone; 293 294 acpi_sc = devclass_get_softc(devclass_find("acpi"), 0); 295 clone = apm_create_clone(dev, acpi_sc); 296 dev->si_drv1 = clone; 297 298 /* If the device is opened for write, record that. */ 299 if ((flag & FWRITE) != 0) 300 clone->flags |= ACPI_EVF_WRITE; 301 302 return (0); 303} 304 305static int 306apmclose(struct cdev *dev, int flag, int fmt, struct thread *td) 307{ 308 struct apm_clone_data *clone; 309 struct acpi_softc *acpi_sc; 310 311 clone = dev->si_drv1; 312 acpi_sc = clone->acpi_sc; 313 314 /* We are about to lose a reference so check if suspend should occur */ 315 if (acpi_sc->acpi_next_sstate != 0 && 316 clone->notify_status != APM_EV_ACKED) 317 acpi_AckSleepState(clone, 0); 318 319 /* Remove this clone's data from the list and free it. */ 320 ACPI_LOCK(acpi); 321 STAILQ_REMOVE(&acpi_sc->apm_cdevs, clone, apm_clone_data, entries); 322 knlist_destroy(&clone->sel_read.si_note); 323 ACPI_UNLOCK(acpi); 324 free(clone, M_APMDEV); 325 destroy_dev_sched(dev); 326 return (0); 327} 328 329static int 330apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td) 331{ 332 int error; 333 struct apm_clone_data *clone; 334 struct acpi_softc *acpi_sc; 335 struct apm_info info; 336 struct apm_event_info *ev_info; 337 apm_info_old_t aiop; 338 339 error = 0; 340 clone = dev->si_drv1; 341 acpi_sc = clone->acpi_sc; 342 343 switch (cmd) { 344 case APMIO_SUSPEND: 345 if ((flag & FWRITE) == 0) 346 return (EPERM); 347 if (acpi_sc->acpi_next_sstate == 0) { 348 if (acpi_sc->acpi_suspend_sx != ACPI_STATE_S5) { 349 error = acpi_ReqSleepState(acpi_sc, 350 acpi_sc->acpi_suspend_sx); 351 } else { 352 printf( 353 "power off via apm suspend not supported\n"); 354 error = ENXIO; 355 } 356 } else 357 error = acpi_AckSleepState(clone, 0); 358 break; 359 case APMIO_STANDBY: 360 if ((flag & FWRITE) == 0) 361 return (EPERM); 362 if (acpi_sc->acpi_next_sstate == 0) { 363 if (acpi_sc->acpi_standby_sx != ACPI_STATE_S5) { 364 error = acpi_ReqSleepState(acpi_sc, 365 acpi_sc->acpi_standby_sx); 366 } else { 367 printf( 368 "power off via apm standby not supported\n"); 369 error = ENXIO; 370 } 371 } else 372 error = acpi_AckSleepState(clone, 0); 373 break; 374 case APMIO_NEXTEVENT: 375 printf("apm nextevent start\n"); 376 ACPI_LOCK(acpi); 377 if (acpi_sc->acpi_next_sstate != 0 && clone->notify_status == 378 APM_EV_NONE) { 379 ev_info = (struct apm_event_info *)addr; 380 if (acpi_sc->acpi_next_sstate <= ACPI_STATE_S3) 381 ev_info->type = PMEV_STANDBYREQ; 382 else 383 ev_info->type = PMEV_SUSPENDREQ; 384 ev_info->index = 0; 385 clone->notify_status = APM_EV_NOTIFIED; 386 printf("apm event returning %d\n", ev_info->type); 387 } else 388 error = EAGAIN; 389 ACPI_UNLOCK(acpi); 390 break; 391 case APMIO_GETINFO_OLD: 392 if (acpi_capm_get_info(&info)) 393 error = ENXIO; 394 aiop = (apm_info_old_t)addr; 395 aiop->ai_major = info.ai_major; 396 aiop->ai_minor = info.ai_minor; 397 aiop->ai_acline = info.ai_acline; 398 aiop->ai_batt_stat = info.ai_batt_stat; 399 aiop->ai_batt_life = info.ai_batt_life; 400 aiop->ai_status = info.ai_status; 401 break; 402 case APMIO_GETINFO: 403 if (acpi_capm_get_info((apm_info_t)addr)) 404 error = ENXIO; 405 break; 406 case APMIO_GETPWSTATUS: 407 if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr)) 408 error = ENXIO; 409 break; 410 case APMIO_ENABLE: 411 if ((flag & FWRITE) == 0) 412 return (EPERM); 413 apm_active = 1; 414 break; 415 case APMIO_DISABLE: 416 if ((flag & FWRITE) == 0) 417 return (EPERM); 418 apm_active = 0; 419 break; 420 case APMIO_HALTCPU: 421 break; 422 case APMIO_NOTHALTCPU: 423 break; 424 case APMIO_DISPLAY: 425 if ((flag & FWRITE) == 0) 426 return (EPERM); 427 break; 428 case APMIO_BIOS: 429 if ((flag & FWRITE) == 0) 430 return (EPERM); 431 bzero(addr, sizeof(struct apm_bios_arg)); 432 break; 433 default: 434 error = EINVAL; 435 break; 436 } 437 438 return (error); 439} 440 441static int 442apmwrite(struct cdev *dev, struct uio *uio, int ioflag) 443{ 444 return (uio->uio_resid); 445} 446 447static int 448apmpoll(struct cdev *dev, int events, struct thread *td) 449{ 450 struct apm_clone_data *clone; 451 int revents; 452 453 revents = 0; 454 ACPI_LOCK(acpi); 455 clone = dev->si_drv1; 456 if (clone->acpi_sc->acpi_next_sstate) 457 revents |= events & (POLLIN | POLLRDNORM); 458 else 459 selrecord(td, &clone->sel_read); 460 ACPI_UNLOCK(acpi); 461 return (revents); 462} 463 464static int 465apmkqfilter(struct cdev *dev, struct knote *kn) 466{ 467 struct apm_clone_data *clone; 468 469 ACPI_LOCK(acpi); 470 clone = dev->si_drv1; 471 kn->kn_hook = clone; 472 kn->kn_fop = &apm_readfiltops; 473 knlist_add(&clone->sel_read.si_note, kn, 0); 474 ACPI_UNLOCK(acpi); 475 return (0); 476} 477 478static void 479apmreadfiltdetach(struct knote *kn) 480{ 481 struct apm_clone_data *clone; 482 483 ACPI_LOCK(acpi); 484 clone = kn->kn_hook; 485 knlist_remove(&clone->sel_read.si_note, kn, 0); 486 ACPI_UNLOCK(acpi); 487} 488 489static int 490apmreadfilt(struct knote *kn, long hint) 491{ 492 struct apm_clone_data *clone; 493 int sleeping; 494 495 ACPI_LOCK(acpi); 496 clone = kn->kn_hook; 497 sleeping = clone->acpi_sc->acpi_next_sstate ? 1 : 0; 498 ACPI_UNLOCK(acpi); 499 return (sleeping); 500} 501 502int 503acpi_machdep_init(device_t dev) 504{ 505 struct acpi_softc *sc; 506 507 sc = devclass_get_softc(devclass_find("acpi"), 0); 508 509 /* Create a clone for /dev/acpi also. */ 510 STAILQ_INIT(&sc->apm_cdevs); 511 sc->acpi_clone = apm_create_clone(sc->acpi_dev_t, sc); 512 clone_setup(&apm_clones); 513 EVENTHANDLER_REGISTER(dev_clone, apm_clone, 0, 1000); 514 acpi_install_wakeup_handler(sc); 515 516 if (intr_model != ACPI_INTR_PIC) 517 acpi_SetIntrModel(intr_model); 518 519 SYSCTL_ADD_UINT(&sc->acpi_sysctl_ctx, 520 SYSCTL_CHILDREN(sc->acpi_sysctl_tree), OID_AUTO, 521 "reset_video", CTLFLAG_RW, &acpi_reset_video, 0, 522 "Call the VESA reset BIOS vector on the resume path"); 523 524 return (0); 525} 526 527void 528acpi_SetDefaultIntrModel(int model) 529{ 530 531 intr_model = model; 532} 533 534int 535acpi_machdep_quirks(int *quirks) 536{ 537 return (0); 538} 539 540void 541acpi_cpu_c1() 542{ 543 __asm __volatile("sti; hlt"); 544} 545 546/* 547 * Support for mapping ACPI tables during early boot. Currently this 548 * uses the crashdump map to map each table. However, the crashdump 549 * map is created in pmap_bootstrap() right after the direct map, so 550 * we should be able to just use pmap_mapbios() here instead. 551 * 552 * This makes the following assumptions about how we use this KVA: 553 * pages 0 and 1 are used to map in the header of each table found via 554 * the RSDT or XSDT and pages 2 to n are used to map in the RSDT or 555 * XSDT. This has to use 2 pages for the table headers in case a 556 * header spans a page boundary. 557 * 558 * XXX: We don't ensure the table fits in the available address space 559 * in the crashdump map. 560 */ 561 562/* 563 * Map some memory using the crashdump map. 'offset' is an offset in 564 * pages into the crashdump map to use for the start of the mapping. 565 */ 566static void * 567table_map(vm_paddr_t pa, int offset, vm_offset_t length) 568{ 569 vm_offset_t va, off; 570 void *data; 571 572 off = pa & PAGE_MASK; 573 length = roundup(length + off, PAGE_SIZE); 574 pa = pa & PG_FRAME; 575 va = (vm_offset_t)pmap_kenter_temporary(pa, offset) + 576 (offset * PAGE_SIZE); 577 data = (void *)(va + off); 578 length -= PAGE_SIZE; 579 while (length > 0) { 580 va += PAGE_SIZE; 581 pa += PAGE_SIZE; 582 length -= PAGE_SIZE; 583 pmap_kenter(va, pa); 584 invlpg(va); 585 } 586 return (data); 587} 588 589/* Unmap memory previously mapped with table_map(). */ 590static void 591table_unmap(void *data, vm_offset_t length) 592{ 593 vm_offset_t va, off; 594 595 va = (vm_offset_t)data; 596 off = va & PAGE_MASK; 597 length = roundup(length + off, PAGE_SIZE); 598 va &= ~PAGE_MASK; 599 while (length > 0) { 600 pmap_kremove(va); 601 invlpg(va); 602 va += PAGE_SIZE; 603 length -= PAGE_SIZE; 604 } 605} 606 607/* 608 * Map a table at a given offset into the crashdump map. It first 609 * maps the header to determine the table length and then maps the 610 * entire table. 611 */ 612static void * 613map_table(vm_paddr_t pa, int offset, const char *sig) 614{ 615 ACPI_TABLE_HEADER *header; 616 vm_offset_t length; 617 void *table; 618 619 header = table_map(pa, offset, sizeof(ACPI_TABLE_HEADER)); 620 if (strncmp(header->Signature, sig, ACPI_NAME_SIZE) != 0) { 621 table_unmap(header, sizeof(ACPI_TABLE_HEADER)); 622 return (NULL); 623 } 624 length = header->Length; 625 table_unmap(header, sizeof(ACPI_TABLE_HEADER)); 626 table = table_map(pa, offset, length); 627 if (ACPI_FAILURE(AcpiTbChecksum(table, length))) { 628 if (bootverbose) 629 printf("ACPI: Failed checksum for table %s\n", sig); 630 table_unmap(table, length); 631 return (NULL); 632 } 633 return (table); 634} 635 636/* 637 * See if a given ACPI table is the requested table. Returns the 638 * length of the able if it matches or zero on failure. 639 */ 640static int 641probe_table(vm_paddr_t address, const char *sig) 642{ 643 ACPI_TABLE_HEADER *table; 644 645 table = table_map(address, 0, sizeof(ACPI_TABLE_HEADER)); 646 if (table == NULL) { 647 if (bootverbose) 648 printf("ACPI: Failed to map table at 0x%jx\n", 649 (uintmax_t)address); 650 return (0); 651 } 652 if (bootverbose) 653 printf("Table '%.4s' at 0x%jx\n", table->Signature, 654 (uintmax_t)address); 655 656 if (strncmp(table->Signature, sig, ACPI_NAME_SIZE) != 0) { 657 table_unmap(table, sizeof(ACPI_TABLE_HEADER)); 658 return (0); 659 } 660 table_unmap(table, sizeof(ACPI_TABLE_HEADER)); 661 return (1); 662} 663 664/* 665 * Try to map a table at a given physical address previously returned 666 * by acpi_find_table(). 667 */ 668void * 669acpi_map_table(vm_paddr_t pa, const char *sig) 670{ 671 672 return (map_table(pa, 0, sig)); 673} 674 675/* Unmap a table previously mapped via acpi_map_table(). */ 676void 677acpi_unmap_table(void *table) 678{ 679 ACPI_TABLE_HEADER *header; 680 681 header = (ACPI_TABLE_HEADER *)table; 682 table_unmap(table, header->Length); 683} 684 685/* 686 * Return the physical address of the requested table or zero if one 687 * is not found. 688 */ 689vm_paddr_t 690acpi_find_table(const char *sig) 691{ 692 ACPI_PHYSICAL_ADDRESS rsdp_ptr; 693 ACPI_TABLE_RSDP *rsdp; 694 ACPI_TABLE_RSDT *rsdt; 695 ACPI_TABLE_XSDT *xsdt; 696 ACPI_TABLE_HEADER *table; 697 vm_paddr_t addr; 698 int i, count; 699 700 if (resource_disabled("acpi", 0)) 701 return (0); 702 703 /* 704 * Map in the RSDP. Since ACPI uses AcpiOsMapMemory() which in turn 705 * calls pmap_mapbios() to find the RSDP, we assume that we can use 706 * pmap_mapbios() to map the RSDP. 707 */ 708 if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0) 709 return (0); 710 rsdp = pmap_mapbios(rsdp_ptr, sizeof(ACPI_TABLE_RSDP)); 711 if (rsdp == NULL) { 712 if (bootverbose) 713 printf("ACPI: Failed to map RSDP\n"); 714 return (0); 715 } 716 717 /* 718 * For ACPI >= 2.0, use the XSDT if it is available. 719 * Otherwise, use the RSDT. We map the XSDT or RSDT at page 2 720 * in the crashdump area. Pages 0 and 1 are used to map in the 721 * headers of candidate ACPI tables. 722 */ 723 addr = 0; 724 if (rsdp->Revision >= 2 && rsdp->XsdtPhysicalAddress != 0) { 725 /* 726 * AcpiOsGetRootPointer only verifies the checksum for 727 * the version 1.0 portion of the RSDP. Version 2.0 has 728 * an additional checksum that we verify first. 729 */ 730 if (AcpiTbChecksum((UINT8 *)rsdp, ACPI_RSDP_XCHECKSUM_LENGTH)) { 731 if (bootverbose) 732 printf("ACPI: RSDP failed extended checksum\n"); 733 return (0); 734 } 735 xsdt = map_table(rsdp->XsdtPhysicalAddress, 2, ACPI_SIG_XSDT); 736 if (xsdt == NULL) { 737 if (bootverbose) 738 printf("ACPI: Failed to map XSDT\n"); 739 return (0); 740 } 741 count = (xsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) / 742 sizeof(UINT64); 743 for (i = 0; i < count; i++) 744 if (probe_table(xsdt->TableOffsetEntry[i], sig)) { 745 addr = xsdt->TableOffsetEntry[i]; 746 break; 747 } 748 acpi_unmap_table(xsdt); 749 } else { 750 rsdt = map_table(rsdp->RsdtPhysicalAddress, 2, ACPI_SIG_RSDT); 751 if (rsdt == NULL) { 752 if (bootverbose) 753 printf("ACPI: Failed to map RSDT\n"); 754 return (0); 755 } 756 count = (rsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) / 757 sizeof(UINT32); 758 for (i = 0; i < count; i++) 759 if (probe_table(rsdt->TableOffsetEntry[i], sig)) { 760 addr = rsdt->TableOffsetEntry[i]; 761 break; 762 } 763 acpi_unmap_table(rsdt); 764 } 765 pmap_unmapbios((vm_offset_t)rsdp, sizeof(ACPI_TABLE_RSDP)); 766 if (addr == 0) { 767 if (bootverbose) 768 printf("ACPI: No %s table found\n", sig); 769 return (0); 770 } 771 if (bootverbose) 772 printf("%s: Found table at 0x%jx\n", sig, (uintmax_t)addr); 773 774 /* 775 * Verify that we can map the full table and that its checksum is 776 * correct, etc. 777 */ 778 table = map_table(addr, 0, sig); 779 if (table == NULL) 780 return (0); 781 acpi_unmap_table(table); 782 783 return (addr); 784} 785 786/* 787 * ACPI nexus(4) driver. 788 */ 789static int 790nexus_acpi_probe(device_t dev) 791{ 792 int error; 793 794 error = acpi_identify(); 795 if (error) 796 return (error); 797 798 return (BUS_PROBE_DEFAULT); 799} 800 801static int 802nexus_acpi_attach(device_t dev) 803{ 804 805 nexus_init_resources(); 806 bus_generic_probe(dev); 807 if (BUS_ADD_CHILD(dev, 10, "acpi", 0) == NULL) 808 panic("failed to add acpi0 device"); 809 810 return (bus_generic_attach(dev)); 811} 812 813static device_method_t nexus_acpi_methods[] = { 814 /* Device interface */ 815 DEVMETHOD(device_probe, nexus_acpi_probe), 816 DEVMETHOD(device_attach, nexus_acpi_attach), 817 818 { 0, 0 } 819}; 820 821DEFINE_CLASS_1(nexus, nexus_acpi_driver, nexus_acpi_methods, 1, nexus_driver); 822static devclass_t nexus_devclass; 823 824DRIVER_MODULE(nexus_acpi, root, nexus_acpi_driver, nexus_devclass, 0, 0); 825