linux/drivers/acpi/bus.c
<<
>>
Prefs
   1/*
   2 *  acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
   3 *
   4 *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
   5 *
   6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   7 *
   8 *  This program is free software; you can redistribute it and/or modify
   9 *  it under the terms of the GNU General Public License as published by
  10 *  the Free Software Foundation; either version 2 of the License, or (at
  11 *  your option) any later version.
  12 *
  13 *  This program is distributed in the hope that it will be useful, but
  14 *  WITHOUT ANY WARRANTY; without even the implied warranty of
  15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16 *  General Public License for more details.
  17 *
  18 *  You should have received a copy of the GNU General Public License along
  19 *  with this program; if not, write to the Free Software Foundation, Inc.,
  20 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  21 *
  22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23 */
  24
  25#include <linux/module.h>
  26#include <linux/init.h>
  27#include <linux/ioport.h>
  28#include <linux/kernel.h>
  29#include <linux/list.h>
  30#include <linux/sched.h>
  31#include <linux/pm.h>
  32#include <linux/device.h>
  33#include <linux/proc_fs.h>
  34#include <linux/acpi.h>
  35#include <linux/slab.h>
  36#ifdef CONFIG_X86
  37#include <asm/mpspec.h>
  38#endif
  39#include <linux/pci.h>
  40#include <acpi/acpi_bus.h>
  41#include <acpi/acpi_drivers.h>
  42#include <acpi/apei.h>
  43#include <linux/dmi.h>
  44#include <linux/suspend.h>
  45
  46#include "internal.h"
  47
  48#define _COMPONENT              ACPI_BUS_COMPONENT
  49ACPI_MODULE_NAME("bus");
  50
  51struct acpi_device *acpi_root;
  52struct proc_dir_entry *acpi_root_dir;
  53EXPORT_SYMBOL(acpi_root_dir);
  54
  55#ifdef CONFIG_X86
  56static int set_copy_dsdt(const struct dmi_system_id *id)
  57{
  58        printk(KERN_NOTICE "%s detected - "
  59                "force copy of DSDT to local memory\n", id->ident);
  60        acpi_gbl_copy_dsdt_locally = 1;
  61        return 0;
  62}
  63
  64static struct dmi_system_id dsdt_dmi_table[] __initdata = {
  65        /*
  66         * Invoke DSDT corruption work-around on all Toshiba Satellite.
  67         * https://bugzilla.kernel.org/show_bug.cgi?id=14679
  68         */
  69        {
  70         .callback = set_copy_dsdt,
  71         .ident = "TOSHIBA Satellite",
  72         .matches = {
  73                DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  74                DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
  75                },
  76        },
  77        {}
  78};
  79#else
  80static struct dmi_system_id dsdt_dmi_table[] __initdata = {
  81        {}
  82};
  83#endif
  84
  85/* --------------------------------------------------------------------------
  86                                Device Management
  87   -------------------------------------------------------------------------- */
  88
  89acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  90                                       unsigned long long *sta)
  91{
  92        acpi_status status;
  93
  94        status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
  95        if (ACPI_SUCCESS(status))
  96                return AE_OK;
  97
  98        if (status == AE_NOT_FOUND) {
  99                *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
 100                       ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING;
 101                return AE_OK;
 102        }
 103        return status;
 104}
 105
 106int acpi_bus_get_status(struct acpi_device *device)
 107{
 108        acpi_status status;
 109        unsigned long long sta;
 110
 111        status = acpi_bus_get_status_handle(device->handle, &sta);
 112        if (ACPI_FAILURE(status))
 113                return -ENODEV;
 114
 115        acpi_set_device_status(device, sta);
 116
 117        if (device->status.functional && !device->status.present) {
 118                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
 119                       "functional but not present;\n",
 120                        device->pnp.bus_id, (u32)sta));
 121        }
 122
 123        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
 124                          device->pnp.bus_id, (u32)sta));
 125        return 0;
 126}
 127EXPORT_SYMBOL(acpi_bus_get_status);
 128
 129void acpi_bus_private_data_handler(acpi_handle handle,
 130                                   void *context)
 131{
 132        return;
 133}
 134EXPORT_SYMBOL(acpi_bus_private_data_handler);
 135
 136int acpi_bus_get_private_data(acpi_handle handle, void **data)
 137{
 138        acpi_status status;
 139
 140        if (!*data)
 141                return -EINVAL;
 142
 143        status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
 144        if (ACPI_FAILURE(status) || !*data) {
 145                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
 146                                handle));
 147                return -ENODEV;
 148        }
 149
 150        return 0;
 151}
 152EXPORT_SYMBOL(acpi_bus_get_private_data);
 153
 154static void acpi_print_osc_error(acpi_handle handle,
 155        struct acpi_osc_context *context, char *error)
 156{
 157        struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
 158        int i;
 159
 160        if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
 161                printk(KERN_DEBUG "%s\n", error);
 162        else {
 163                printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
 164                kfree(buffer.pointer);
 165        }
 166        printk(KERN_DEBUG"_OSC request data:");
 167        for (i = 0; i < context->cap.length; i += sizeof(u32))
 168                printk("%x ", *((u32 *)(context->cap.pointer + i)));
 169        printk("\n");
 170}
 171
 172acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
 173{
 174        int i;
 175        static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
 176                24, 26, 28, 30, 32, 34};
 177
 178        if (strlen(str) != 36)
 179                return AE_BAD_PARAMETER;
 180        for (i = 0; i < 36; i++) {
 181                if (i == 8 || i == 13 || i == 18 || i == 23) {
 182                        if (str[i] != '-')
 183                                return AE_BAD_PARAMETER;
 184                } else if (!isxdigit(str[i]))
 185                        return AE_BAD_PARAMETER;
 186        }
 187        for (i = 0; i < 16; i++) {
 188                uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
 189                uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
 190        }
 191        return AE_OK;
 192}
 193EXPORT_SYMBOL_GPL(acpi_str_to_uuid);
 194
 195acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
 196{
 197        acpi_status status;
 198        struct acpi_object_list input;
 199        union acpi_object in_params[4];
 200        union acpi_object *out_obj;
 201        u8 uuid[16];
 202        u32 errors;
 203        struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
 204
 205        if (!context)
 206                return AE_ERROR;
 207        if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
 208                return AE_ERROR;
 209        context->ret.length = ACPI_ALLOCATE_BUFFER;
 210        context->ret.pointer = NULL;
 211
 212        /* Setting up input parameters */
 213        input.count = 4;
 214        input.pointer = in_params;
 215        in_params[0].type               = ACPI_TYPE_BUFFER;
 216        in_params[0].buffer.length      = 16;
 217        in_params[0].buffer.pointer     = uuid;
 218        in_params[1].type               = ACPI_TYPE_INTEGER;
 219        in_params[1].integer.value      = context->rev;
 220        in_params[2].type               = ACPI_TYPE_INTEGER;
 221        in_params[2].integer.value      = context->cap.length/sizeof(u32);
 222        in_params[3].type               = ACPI_TYPE_BUFFER;
 223        in_params[3].buffer.length      = context->cap.length;
 224        in_params[3].buffer.pointer     = context->cap.pointer;
 225
 226        status = acpi_evaluate_object(handle, "_OSC", &input, &output);
 227        if (ACPI_FAILURE(status))
 228                return status;
 229
 230        if (!output.length)
 231                return AE_NULL_OBJECT;
 232
 233        out_obj = output.pointer;
 234        if (out_obj->type != ACPI_TYPE_BUFFER
 235                || out_obj->buffer.length != context->cap.length) {
 236                acpi_print_osc_error(handle, context,
 237                        "_OSC evaluation returned wrong type");
 238                status = AE_TYPE;
 239                goto out_kfree;
 240        }
 241        /* Need to ignore the bit0 in result code */
 242        errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
 243        if (errors) {
 244                if (errors & OSC_REQUEST_ERROR)
 245                        acpi_print_osc_error(handle, context,
 246                                "_OSC request failed");
 247                if (errors & OSC_INVALID_UUID_ERROR)
 248                        acpi_print_osc_error(handle, context,
 249                                "_OSC invalid UUID");
 250                if (errors & OSC_INVALID_REVISION_ERROR)
 251                        acpi_print_osc_error(handle, context,
 252                                "_OSC invalid revision");
 253                if (errors & OSC_CAPABILITIES_MASK_ERROR) {
 254                        if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD]
 255                            & OSC_QUERY_ENABLE)
 256                                goto out_success;
 257                        status = AE_SUPPORT;
 258                        goto out_kfree;
 259                }
 260                status = AE_ERROR;
 261                goto out_kfree;
 262        }
 263out_success:
 264        context->ret.length = out_obj->buffer.length;
 265        context->ret.pointer = kmemdup(out_obj->buffer.pointer,
 266                                       context->ret.length, GFP_KERNEL);
 267        if (!context->ret.pointer) {
 268                status =  AE_NO_MEMORY;
 269                goto out_kfree;
 270        }
 271        status =  AE_OK;
 272
 273out_kfree:
 274        kfree(output.pointer);
 275        if (status != AE_OK)
 276                context->ret.pointer = NULL;
 277        return status;
 278}
 279EXPORT_SYMBOL(acpi_run_osc);
 280
 281bool osc_sb_apei_support_acked;
 282static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
 283static void acpi_bus_osc_support(void)
 284{
 285        u32 capbuf[2];
 286        struct acpi_osc_context context = {
 287                .uuid_str = sb_uuid_str,
 288                .rev = 1,
 289                .cap.length = 8,
 290                .cap.pointer = capbuf,
 291        };
 292        acpi_handle handle;
 293
 294        capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
 295        capbuf[OSC_SUPPORT_DWORD] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
 296        if (IS_ENABLED(CONFIG_ACPI_PROCESSOR_AGGREGATOR))
 297                capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PAD_SUPPORT;
 298        if (IS_ENABLED(CONFIG_ACPI_PROCESSOR))
 299                capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
 300
 301        capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
 302
 303        if (!ghes_disable)
 304                capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
 305        if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
 306                return;
 307        if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
 308                u32 *capbuf_ret = context.ret.pointer;
 309                if (context.ret.length > OSC_SUPPORT_DWORD)
 310                        osc_sb_apei_support_acked =
 311                                capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
 312                kfree(context.ret.pointer);
 313        }
 314        /* do we need to check other returned cap? Sounds no */
 315}
 316
 317/* --------------------------------------------------------------------------
 318                                Event Management
 319   -------------------------------------------------------------------------- */
 320
 321#ifdef CONFIG_ACPI_PROC_EVENT
 322static DEFINE_SPINLOCK(acpi_bus_event_lock);
 323
 324LIST_HEAD(acpi_bus_event_list);
 325DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
 326
 327extern int event_is_open;
 328
 329int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
 330{
 331        struct acpi_bus_event *event;
 332        unsigned long flags;
 333
 334        /* drop event on the floor if no one's listening */
 335        if (!event_is_open)
 336                return 0;
 337
 338        event = kzalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
 339        if (!event)
 340                return -ENOMEM;
 341
 342        strcpy(event->device_class, device_class);
 343        strcpy(event->bus_id, bus_id);
 344        event->type = type;
 345        event->data = data;
 346
 347        spin_lock_irqsave(&acpi_bus_event_lock, flags);
 348        list_add_tail(&event->node, &acpi_bus_event_list);
 349        spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
 350
 351        wake_up_interruptible(&acpi_bus_event_queue);
 352
 353        return 0;
 354
 355}
 356
 357EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
 358
 359int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
 360{
 361        if (!device)
 362                return -EINVAL;
 363        return acpi_bus_generate_proc_event4(device->pnp.device_class,
 364                                             device->pnp.bus_id, type, data);
 365}
 366
 367EXPORT_SYMBOL(acpi_bus_generate_proc_event);
 368
 369int acpi_bus_receive_event(struct acpi_bus_event *event)
 370{
 371        unsigned long flags;
 372        struct acpi_bus_event *entry = NULL;
 373
 374        DECLARE_WAITQUEUE(wait, current);
 375
 376
 377        if (!event)
 378                return -EINVAL;
 379
 380        if (list_empty(&acpi_bus_event_list)) {
 381
 382                set_current_state(TASK_INTERRUPTIBLE);
 383                add_wait_queue(&acpi_bus_event_queue, &wait);
 384
 385                if (list_empty(&acpi_bus_event_list))
 386                        schedule();
 387
 388                remove_wait_queue(&acpi_bus_event_queue, &wait);
 389                set_current_state(TASK_RUNNING);
 390
 391                if (signal_pending(current))
 392                        return -ERESTARTSYS;
 393        }
 394
 395        spin_lock_irqsave(&acpi_bus_event_lock, flags);
 396        if (!list_empty(&acpi_bus_event_list)) {
 397                entry = list_entry(acpi_bus_event_list.next,
 398                                   struct acpi_bus_event, node);
 399                list_del(&entry->node);
 400        }
 401        spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
 402
 403        if (!entry)
 404                return -ENODEV;
 405
 406        memcpy(event, entry, sizeof(struct acpi_bus_event));
 407
 408        kfree(entry);
 409
 410        return 0;
 411}
 412
 413#endif  /* CONFIG_ACPI_PROC_EVENT */
 414
 415/* --------------------------------------------------------------------------
 416                             Notification Handling
 417   -------------------------------------------------------------------------- */
 418
 419/**
 420 * acpi_bus_notify
 421 * ---------------
 422 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
 423 */
 424static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
 425{
 426        struct acpi_device *adev;
 427        struct acpi_driver *driver;
 428        acpi_status status;
 429        u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
 430
 431        switch (type) {
 432        case ACPI_NOTIFY_BUS_CHECK:
 433                acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n");
 434                break;
 435
 436        case ACPI_NOTIFY_DEVICE_CHECK:
 437                acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n");
 438                break;
 439
 440        case ACPI_NOTIFY_DEVICE_WAKE:
 441                acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_WAKE event\n");
 442                break;
 443
 444        case ACPI_NOTIFY_EJECT_REQUEST:
 445                acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
 446                break;
 447
 448        case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
 449                acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK_LIGHT event\n");
 450                /* TBD: Exactly what does 'light' mean? */
 451                break;
 452
 453        case ACPI_NOTIFY_FREQUENCY_MISMATCH:
 454                acpi_handle_err(handle, "Device cannot be configured due "
 455                                "to a frequency mismatch\n");
 456                break;
 457
 458        case ACPI_NOTIFY_BUS_MODE_MISMATCH:
 459                acpi_handle_err(handle, "Device cannot be configured due "
 460                                "to a bus mode mismatch\n");
 461                break;
 462
 463        case ACPI_NOTIFY_POWER_FAULT:
 464                acpi_handle_err(handle, "Device has suffered a power fault\n");
 465                break;
 466
 467        default:
 468                acpi_handle_warn(handle, "Unsupported event type 0x%x\n", type);
 469                ost_code = ACPI_OST_SC_UNRECOGNIZED_NOTIFY;
 470                goto err;
 471        }
 472
 473        adev = acpi_bus_get_acpi_device(handle);
 474        if (!adev)
 475                goto err;
 476
 477        driver = adev->driver;
 478        if (driver && driver->ops.notify &&
 479            (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
 480                driver->ops.notify(adev, type);
 481
 482        switch (type) {
 483        case ACPI_NOTIFY_BUS_CHECK:
 484        case ACPI_NOTIFY_DEVICE_CHECK:
 485        case ACPI_NOTIFY_EJECT_REQUEST:
 486                status = acpi_hotplug_schedule(adev, type);
 487                if (ACPI_SUCCESS(status))
 488                        return;
 489        default:
 490                break;
 491        }
 492        acpi_bus_put_acpi_device(adev);
 493        return;
 494
 495 err:
 496        acpi_evaluate_ost(handle, type, ost_code, NULL);
 497}
 498
 499/* --------------------------------------------------------------------------
 500                             Initialization/Cleanup
 501   -------------------------------------------------------------------------- */
 502
 503static int __init acpi_bus_init_irq(void)
 504{
 505        acpi_status status;
 506        char *message = NULL;
 507
 508
 509        /*
 510         * Let the system know what interrupt model we are using by
 511         * evaluating the \_PIC object, if exists.
 512         */
 513
 514        switch (acpi_irq_model) {
 515        case ACPI_IRQ_MODEL_PIC:
 516                message = "PIC";
 517                break;
 518        case ACPI_IRQ_MODEL_IOAPIC:
 519                message = "IOAPIC";
 520                break;
 521        case ACPI_IRQ_MODEL_IOSAPIC:
 522                message = "IOSAPIC";
 523                break;
 524        case ACPI_IRQ_MODEL_PLATFORM:
 525                message = "platform specific model";
 526                break;
 527        default:
 528                printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
 529                return -ENODEV;
 530        }
 531
 532        printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
 533
 534        status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model);
 535        if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
 536                ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
 537                return -ENODEV;
 538        }
 539
 540        return 0;
 541}
 542
 543u8 acpi_gbl_permanent_mmap;
 544
 545
 546void __init acpi_early_init(void)
 547{
 548        acpi_status status;
 549
 550        if (acpi_disabled)
 551                return;
 552
 553        printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
 554
 555        /* It's safe to verify table checksums during late stage */
 556        acpi_gbl_verify_table_checksum = TRUE;
 557
 558        /* enable workarounds, unless strict ACPI spec. compliance */
 559        if (!acpi_strict)
 560                acpi_gbl_enable_interpreter_slack = TRUE;
 561
 562        acpi_gbl_permanent_mmap = 1;
 563
 564        /*
 565         * If the machine falls into the DMI check table,
 566         * DSDT will be copied to memory
 567         */
 568        dmi_check_system(dsdt_dmi_table);
 569
 570        status = acpi_reallocate_root_table();
 571        if (ACPI_FAILURE(status)) {
 572                printk(KERN_ERR PREFIX
 573                       "Unable to reallocate ACPI tables\n");
 574                goto error0;
 575        }
 576
 577        status = acpi_initialize_subsystem();
 578        if (ACPI_FAILURE(status)) {
 579                printk(KERN_ERR PREFIX
 580                       "Unable to initialize the ACPI Interpreter\n");
 581                goto error0;
 582        }
 583
 584        status = acpi_load_tables();
 585        if (ACPI_FAILURE(status)) {
 586                printk(KERN_ERR PREFIX
 587                       "Unable to load the System Description Tables\n");
 588                goto error0;
 589        }
 590
 591#ifdef CONFIG_X86
 592        if (!acpi_ioapic) {
 593                /* compatible (0) means level (3) */
 594                if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
 595                        acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
 596                        acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
 597                }
 598                /* Set PIC-mode SCI trigger type */
 599                acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
 600                                         (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
 601        } else {
 602                /*
 603                 * now that acpi_gbl_FADT is initialized,
 604                 * update it with result from INT_SRC_OVR parsing
 605                 */
 606                acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
 607        }
 608#endif
 609
 610        status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
 611        if (ACPI_FAILURE(status)) {
 612                printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
 613                goto error0;
 614        }
 615
 616        return;
 617
 618      error0:
 619        disable_acpi();
 620        return;
 621}
 622
 623static int __init acpi_bus_init(void)
 624{
 625        int result;
 626        acpi_status status;
 627
 628        acpi_os_initialize1();
 629
 630        status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
 631        if (ACPI_FAILURE(status)) {
 632                printk(KERN_ERR PREFIX
 633                       "Unable to start the ACPI Interpreter\n");
 634                goto error1;
 635        }
 636
 637        /*
 638         * ACPI 2.0 requires the EC driver to be loaded and work before
 639         * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
 640         * is called).
 641         *
 642         * This is accomplished by looking for the ECDT table, and getting
 643         * the EC parameters out of that.
 644         */
 645        status = acpi_ec_ecdt_probe();
 646        /* Ignore result. Not having an ECDT is not fatal. */
 647
 648        status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
 649        if (ACPI_FAILURE(status)) {
 650                printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
 651                goto error1;
 652        }
 653
 654        /* Set capability bits for _OSC under processor scope */
 655        acpi_early_processor_osc();
 656
 657        /*
 658         * _OSC method may exist in module level code,
 659         * so it must be run after ACPI_FULL_INITIALIZATION
 660         */
 661        acpi_bus_osc_support();
 662
 663        /*
 664         * _PDC control method may load dynamic SSDT tables,
 665         * and we need to install the table handler before that.
 666         */
 667        acpi_sysfs_init();
 668
 669        acpi_early_processor_set_pdc();
 670
 671        /*
 672         * Maybe EC region is required at bus_scan/acpi_get_devices. So it
 673         * is necessary to enable it as early as possible.
 674         */
 675        acpi_boot_ec_enable();
 676
 677        printk(KERN_INFO PREFIX "Interpreter enabled\n");
 678
 679        /* Initialize sleep structures */
 680        acpi_sleep_init();
 681
 682        /*
 683         * Get the system interrupt model and evaluate \_PIC.
 684         */
 685        result = acpi_bus_init_irq();
 686        if (result)
 687                goto error1;
 688
 689        /*
 690         * Register the for all standard device notifications.
 691         */
 692        status =
 693            acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
 694                                        &acpi_bus_notify, NULL);
 695        if (ACPI_FAILURE(status)) {
 696                printk(KERN_ERR PREFIX
 697                       "Unable to register for device notifications\n");
 698                goto error1;
 699        }
 700
 701        /*
 702         * Create the top ACPI proc directory
 703         */
 704        acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
 705
 706        return 0;
 707
 708        /* Mimic structured exception handling */
 709      error1:
 710        acpi_terminate();
 711        return -ENODEV;
 712}
 713
 714struct kobject *acpi_kobj;
 715EXPORT_SYMBOL_GPL(acpi_kobj);
 716
 717static int __init acpi_init(void)
 718{
 719        int result;
 720
 721        if (acpi_disabled) {
 722                printk(KERN_INFO PREFIX "Interpreter disabled.\n");
 723                return -ENODEV;
 724        }
 725
 726        acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
 727        if (!acpi_kobj) {
 728                printk(KERN_WARNING "%s: kset create error\n", __func__);
 729                acpi_kobj = NULL;
 730        }
 731
 732        init_acpi_device_notify();
 733        result = acpi_bus_init();
 734        if (result) {
 735                disable_acpi();
 736                return result;
 737        }
 738
 739        pci_mmcfg_late_init();
 740        acpi_scan_init();
 741        acpi_ec_init();
 742        acpi_debugfs_init();
 743        acpi_sleep_proc_init();
 744        acpi_wakeup_device_init();
 745        return 0;
 746}
 747
 748subsys_initcall(acpi_init);
 749