Subversion Repositories Kolibri OS

Rev

Rev 1500 | Rev 1627 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1498 serge 1
 
1625 serge 2
#include 
3
#include 
4
#include 
5
#include 
1498 serge 6
7
 
8
9
 
1625 serge 10
#define ACPI_BUS_HID            "KLBSYBUS"
11
#define ACPI_BUS_DEVICE_NAME    "System Bus"
12
13
 
14
 
15
16
 
17
static LIST_HEAD(acpi_bus_id_list);
18
DEFINE_MUTEX(acpi_device_lock);
19
20
 
21
{
22
    char bus_id[15];
23
    unsigned int instance_no;
24
    struct list_head node;
25
};
26
27
 
28
 
1498 serge 29
#define ACPI_NS_SYSTEM_BUS      "_SB_"
30
31
 
32
	ACPI_IRQ_MODEL_PIC = 0,
33
	ACPI_IRQ_MODEL_IOAPIC,
34
	ACPI_IRQ_MODEL_IOSAPIC,
35
	ACPI_IRQ_MODEL_PLATFORM,
36
	ACPI_IRQ_MODEL_COUNT
37
};
38
39
 
1625 serge 40
    ACPI_BUS_REMOVAL_NORMAL = 0,
41
    ACPI_BUS_REMOVAL_EJECT,
42
    ACPI_BUS_REMOVAL_SUPRISE,
43
    ACPI_BUS_REMOVAL_TYPE_COUNT
44
};
45
1498 serge 46
 
1625 serge 47
    ACPI_BUS_TYPE_DEVICE = 0,
48
    ACPI_BUS_TYPE_POWER,
49
    ACPI_BUS_TYPE_PROCESSOR,
50
    ACPI_BUS_TYPE_THERMAL,
51
    ACPI_BUS_TYPE_POWER_BUTTON,
52
    ACPI_BUS_TYPE_SLEEP_BUTTON,
53
    ACPI_BUS_DEVICE_TYPE_COUNT
54
};
55
56
 
57
 * _HID definitions
58
 * HIDs must conform to ACPI spec(6.1.4)
59
 * KolibriOS specific HIDs do not apply to this and begin with KOS:
60
 */
61
62
 
63
#define ACPI_PROCESSOR_OBJECT_HID   "KLBCPU"
64
#define ACPI_SYSTEM_HID             "KLBSYSTM"
65
#define ACPI_THERMAL_HID            "KLBTHERM"
66
#define ACPI_BUTTON_HID_POWERF      "KLBPWRBN"
67
#define ACPI_BUTTON_HID_SLEEPF      "KLBSLPBN"
68
#define ACPI_VIDEO_HID              "KLBVIDEO"
69
#define ACPI_BAY_HID                "KLBIOBAY"
70
#define ACPI_DOCK_HID               "KLBDOCK"
71
/* Quirk for broken IBM BIOSes */
72
#define ACPI_SMBUS_IBM_HID      "SMBUSIBM"
73
74
 
75
 
76
77
 
78
              ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING)
79
80
 
81
#define PCI_MAX_PINS    4
82
83
 
84
85
 
86
static ACPI_HANDLE pci_root_handle;
87
88
 
89
 
1498 serge 90
    (addr_t)((addr_t)(addr) + (addr_t)(off))
91
92
 
93
//    (addr_t)((addr_t)(addr) + OS_BASE)
94
95
 
96
97
 
1625 serge 98
 
99
{
100
    u32_t acpi_op_add:1;
101
    u32_t acpi_op_start:1;
102
};
103
104
 
105
    u32 dynamic_status:1;
106
    u32 bus_address:1;
107
    u32 removable:1;
108
    u32 ejectable:1;
109
    u32 lockable:1;
110
    u32 suprise_removal_ok:1;
111
    u32 power_manageable:1;
112
    u32 performance_manageable:1;
113
    u32 wake_capable:1; /* Wakeup(_PRW) supported? */
114
    u32 force_power_state:1;
115
    u32 reserved:22;
116
};
117
118
 
119
    u32 present:1;
120
    u32 enabled:1;
121
    u32 show_in_ui:1;
122
    u32 functional:1;
123
    u32 battery_present:1;
124
    u32 reserved:27;
125
};
126
127
 
128
 
129
typedef unsigned long acpi_bus_address;
130
typedef char acpi_device_name[40];
131
typedef char acpi_device_class[20];
132
133
 
134
    struct list_head list;
135
    char *id;
136
};
137
138
 
139
{
140
    acpi_bus_id       bus_id;       /* Object name */
141
    acpi_bus_address  bus_address;  /* _ADR */
142
    char *unique_id;                /* _UID */
143
    struct list_head  ids;          /* _HID and _CIDs */
144
    acpi_device_name  device_name;  /* Driver-determined */
145
    acpi_device_class device_class; /*        "          */
146
};
147
148
 
149
 
150
{
151
    int device_type;
152
    ACPI_HANDLE handle;     /* no handle for fixed hardware */
153
    struct acpi_device *parent;
154
    struct list_head children;
155
    struct list_head node;
156
//    struct list_head wakeup_list;
157
    struct acpi_device_status status;
158
    struct acpi_device_flags flags;
159
    struct acpi_device_pnp pnp;
160
//    struct acpi_device_power power;
161
//    struct acpi_device_wakeup wakeup;
162
//    struct acpi_device_perf performance;
163
//    struct acpi_device_dir dir;
164
//    struct acpi_device_ops ops;
165
//    struct acpi_driver *driver;
166
    void *driver_data;
167
//    struct device dev;
168
    struct acpi_bus_ops bus_ops;    /* workaround for different code path for hotplug */
169
 //   enum acpi_bus_removal_type removal_type;    /* indicate for different removal type */
170
};
171
172
 
173
174
 
175
 
176
acpi_util_eval_error(ACPI_HANDLE h, ACPI_STRING p, ACPI_STATUS s)
177
{
178
#ifdef ACPI_DEBUG_OUTPUT
179
    char prefix[80] = {'\0'};
180
    ACPI_BUFFER buffer = {sizeof(prefix), prefix};
181
    AcpiGetName(h, ACPI_FULL_PATHNAME, &buffer);
182
    ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate [%s.%s]: %s\n",
183
        (char *) prefix, p, AcpiFormatException(s)));
184
#else
185
    return;
186
#endif
187
}
188
189
 
1498 serge 190
acpi_evaluate_integer(ACPI_HANDLE handle, ACPI_STRING pathname,
1625 serge 191
              ACPI_OBJECT_LIST *arguments, unsigned long long *data)
192
{
1498 serge 193
    ACPI_STATUS status = AE_OK;
1625 serge 194
    ACPI_OBJECT element;
195
    ACPI_BUFFER buffer = { 0, NULL };
196
1498 serge 197
 
1625 serge 198
        return AE_BAD_PARAMETER;
199
1498 serge 200
 
1625 serge 201
    buffer.Pointer = &element;
202
    status = AcpiEvaluateObject(handle, pathname, arguments, &buffer);
203
    if (ACPI_FAILURE(status)) {
204
        acpi_util_eval_error(handle, pathname, status);
205
        return status;
206
    }
207
1498 serge 208
 
1625 serge 209
        acpi_util_eval_error(handle, pathname, AE_BAD_DATA);
210
        return AE_BAD_DATA;
211
    }
212
1498 serge 213
 
1625 serge 214
1498 serge 215
 
1625 serge 216
1498 serge 217
 
1625 serge 218
}
219
220
 
221
{
222
223
 
224
225
 
226
}
227
228
 
229
 
230
{
231
    ACPI_STATUS status = AE_OK;
232
233
 
234
    {
235
        return -EINVAL;
236
    };
237
238
 
239
240
 
241
    if (ACPI_FAILURE(status) || !*device) {
242
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
243
                  handle));
244
        return -ENODEV;
245
    }
1498 serge 246
    return 0;
1625 serge 247
}
248
1498 serge 249
 
250
 
1625 serge 251
                       unsigned long long *sta)
252
{
253
    ACPI_STATUS status;
254
1498 serge 255
 
1625 serge 256
    if (ACPI_SUCCESS(status))
257
    {
258
        return AE_OK;
259
    };
260
1498 serge 261
 
1625 serge 262
    {
1498 serge 263
        *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
1625 serge 264
               ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING;
265
        return AE_OK;
266
    }
267
    return status;
268
}
269
1500 serge 270
 
1625 serge 271
 
272
 
273
                    unsigned long long *sta)
274
{
275
    ACPI_STATUS status;
276
    ACPI_OBJECT_TYPE acpi_type;
277
278
 
279
    if (ACPI_FAILURE(status))
280
    {
281
        return -ENODEV;
282
    };
1498 serge 283
284
 
1625 serge 285
    {
286
        case ACPI_TYPE_ANY:     /* for ACPI_ROOT_OBJECT */
287
        case ACPI_TYPE_DEVICE:
288
            *type = ACPI_BUS_TYPE_DEVICE;
289
            status = acpi_bus_get_status_handle(handle, sta);
290
            if (ACPI_FAILURE(status))
291
            {
292
                return -ENODEV;
293
            };
294
            break;
295
1498 serge 296
 
1625 serge 297
            *type = ACPI_BUS_TYPE_PROCESSOR;
298
            status = acpi_bus_get_status_handle(handle, sta);
299
            if (ACPI_FAILURE(status))
300
            {
301
                return -ENODEV;
302
            };
303
            break;
304
        case ACPI_TYPE_THERMAL:
305
            *type = ACPI_BUS_TYPE_THERMAL;
306
            *sta = ACPI_STA_DEFAULT;
307
            break;
308
        case ACPI_TYPE_POWER:
309
            *type = ACPI_BUS_TYPE_POWER;
310
            *sta = ACPI_STA_DEFAULT;
311
            break;
312
        default:
313
            return -ENODEV;
314
    }
315
316
 
317
}
1498 serge 318
319
 
1625 serge 320
{
1498 serge 321
    ACPI_STATUS status;
1625 serge 322
    struct      acpi_device *device;
323
    int         ret;
324
1498 serge 325
 
1625 serge 326
     * Fixed hardware devices do not appear in the namespace and do not
327
     * have handles, but we fabricate acpi_devices for them, so we have
328
     * to deal with them specially.
329
     */
330
    if (handle == NULL)
331
    {
332
        return acpi_root;
333
    };
334
335
 
336
    {
337
        status = AcpiGetParent(handle, &handle);
338
        if (status == AE_NULL_ENTRY)
339
        {
340
            return NULL;
341
        };
342
        if (ACPI_FAILURE(status))
343
        {
344
            return acpi_root;
345
        };
346
347
 
348
        if (ret == 0)
349
        {
350
            return device;
351
        };
352
    } while (1);
353
}
354
355
 
356
 
357
{
358
    char bus_id[5] = { '?', 0 };
359
    struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
360
    int i = 0;
361
362
 
363
     * Bus ID
364
     * ------
365
     * The device's Bus ID is simply the object name.
366
     * TBD: Shouldn't this value be unique (within the ACPI namespace)?
367
     */
368
    if (ACPI_IS_ROOT_DEVICE(device)) {
369
        strcpy(device->pnp.bus_id, "ACPI");
370
        return;
1498 serge 371
    }
1625 serge 372
1498 serge 373
 
1625 serge 374
    {
1498 serge 375
        case ACPI_BUS_TYPE_POWER_BUTTON:
1625 serge 376
            strcpy(device->pnp.bus_id, "PWRF");
377
            break;
378
        case ACPI_BUS_TYPE_SLEEP_BUTTON:
379
            strcpy(device->pnp.bus_id, "SLPF");
380
            break;
381
        default:
382
            AcpiGetName(device->handle, ACPI_SINGLE_NAME, &buffer);
383
        /* Clean up trailing underscores (if any) */
384
            for (i = 3; i > 1; i--)
385
            {
386
                if (bus_id[i] == '_')
387
                    bus_id[i] = '\0';
388
                else
389
                    break;
390
            }
391
            strcpy(device->pnp.bus_id, bus_id);
392
            break;
393
    }
394
}
395
1498 serge 396
 
397
 
1625 serge 398
{
399
    ACPI_STATUS status = AE_OK;
400
    ACPI_HANDLE temp   = NULL;
401
402
 
403
    status = AcpiGetHandle(device->handle, "_STA", &temp);
404
    if (ACPI_SUCCESS(status))
405
        device->flags.dynamic_status = 1;
406
407
 
408
    status = AcpiGetHandle(device->handle, "_RMV", &temp);
409
    if (ACPI_SUCCESS(status))
410
        device->flags.removable = 1;
411
412
 
413
    status = AcpiGetHandle(device->handle, "_EJD", &temp);
414
    if (ACPI_SUCCESS(status))
415
        device->flags.ejectable = 1;
416
    else {
417
        status = AcpiGetHandle(device->handle, "_EJ0", &temp);
418
        if (ACPI_SUCCESS(status))
419
            device->flags.ejectable = 1;
420
    }
1498 serge 421
1625 serge 422
 
423
    status = AcpiGetHandle(device->handle, "_LCK", &temp);
424
    if (ACPI_SUCCESS(status))
425
        device->flags.lockable = 1;
426
427
 
428
    status = AcpiGetHandle(device->handle, "_PS0", &temp);
429
    if (ACPI_FAILURE(status))
430
        status = AcpiGetHandle(device->handle, "_PR0", &temp);
431
    if (ACPI_SUCCESS(status))
432
        device->flags.power_manageable = 1;
433
434
 
435
    status = AcpiGetHandle(device->handle, "_PRW", &temp);
436
    if (ACPI_SUCCESS(status))
437
        device->flags.wake_capable = 1;
438
439
 
440
441
 
442
}
1498 serge 443
444
 
1625 serge 445
 * acpi_bay_match - see if a device is an ejectable driver bay
446
 *
447
 * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
448
 * then we can safely call it an ejectable drive bay
449
 */
450
static int acpi_bay_match(struct acpi_device *device){
451
    ACPI_STATUS status;
452
    ACPI_HANDLE handle;
453
    ACPI_HANDLE tmp;
454
    ACPI_HANDLE phandle;
455
1498 serge 456
 
1625 serge 457
458
 
459
    if (ACPI_FAILURE(status))
460
        return -ENODEV;
461
462
 
463
        (ACPI_SUCCESS(AcpiGetHandle(handle, "_GTM", &tmp))) ||
464
        (ACPI_SUCCESS(AcpiGetHandle(handle, "_STM", &tmp))) ||
465
        (ACPI_SUCCESS(AcpiGetHandle(handle, "_SDD", &tmp))))
466
        return 0;
467
468
 
469
        return -ENODEV;
470
471
 
472
        (ACPI_SUCCESS(AcpiGetHandle(phandle, "_GTM", &tmp))) ||
473
        (ACPI_SUCCESS(AcpiGetHandle(phandle, "_STM", &tmp))) ||
474
        (ACPI_SUCCESS(AcpiGetHandle(phandle, "_SDD", &tmp))))
475
        return 0;
476
477
 
478
}
479
480
 
481
 * acpi_dock_match - see if a device has a _DCK method
482
 */
483
static int acpi_dock_match(struct acpi_device *device)
484
{
485
    ACPI_HANDLE tmp;
486
    return AcpiGetHandle(device->handle, "_DCK", &tmp);
487
}
488
489
 
490
{
491
    struct acpi_hardware_id *hid;
492
493
 
494
    return hid->id;
495
}
496
497
 
498
 
499
 
500
{
501
    struct acpi_hardware_id *id;
502
503
 
504
    if (!id)
505
    {
506
        return;
507
    };
508
509
 
510
511
 
512
    if (!id->id) {
513
        kfree(id);
514
        return;
515
    }
516
517
 
518
519
 
520
}
521
522
 
523
#define ACPI_VIDEO_DEVICE_POSTING           0x0002
524
#define ACPI_VIDEO_ROM_AVAILABLE            0x0004
525
#define ACPI_VIDEO_BACKLIGHT                0x0008
526
#define ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR       0x0010
527
#define ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO        0x0020
528
#define ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VENDOR    0x0040
529
#define ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VIDEO     0x0080
530
#define ACPI_VIDEO_BACKLIGHT_DMI_VENDOR         0x0100
531
#define ACPI_VIDEO_BACKLIGHT_DMI_VIDEO          0x0200
532
#define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VENDOR      0x0400
533
#define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VIDEO       0x0800
534
535
 
536
 
537
{
538
    ACPI_HANDLE h_dummy;
539
    long video_caps = 0;
540
541
 
542
        return 0;
543
544
 
545
    if (ACPI_SUCCESS(AcpiGetHandle(device->handle, "_DOD", &h_dummy)) ||
546
        ACPI_SUCCESS(AcpiGetHandle(device->handle, "_DOS", &h_dummy)))
547
        video_caps |= ACPI_VIDEO_OUTPUT_SWITCHING;
548
549
 
550
    if (ACPI_SUCCESS(AcpiGetHandle(device->handle, "_ROM", &h_dummy)))
551
        video_caps |= ACPI_VIDEO_ROM_AVAILABLE;
552
553
 
554
    if (ACPI_SUCCESS(AcpiGetHandle(device->handle, "_VPO", &h_dummy)) &&
555
        ACPI_SUCCESS(AcpiGetHandle(device->handle, "_GPD", &h_dummy)) &&
556
        ACPI_SUCCESS(AcpiGetHandle(device->handle, "_SPD", &h_dummy)))
557
        video_caps |= ACPI_VIDEO_DEVICE_POSTING;
558
559
 
560
}
561
562
 
563
 
564
{
565
    ACPI_STATUS status;
566
    ACPI_DEVICE_INFO *info;
567
    ACPI_DEVICE_ID_LIST *cid_list;
568
    int i;
569
570
 
571
    {
572
        case ACPI_BUS_TYPE_DEVICE:
573
            if (ACPI_IS_ROOT_DEVICE(device))
574
            {
575
                acpi_add_id(device, ACPI_SYSTEM_HID);
576
                break;
577
            }
578
579
 
580
            if (ACPI_FAILURE(status)) {
581
                printk(KERN_ERR "%s: Error reading device info\n", __func__);
582
                return;
583
            }
584
585
 
586
                acpi_add_id(device, info->HardwareId.String);
587
            if (info->Valid & ACPI_VALID_CID)
588
            {
589
                cid_list = &info->CompatibleIdList;
590
                for (i = 0; i < cid_list->Count; i++)
591
                    acpi_add_id(device, cid_list->Ids[i].String);
592
            }
593
            if (info->Valid & ACPI_VALID_ADR) {
594
                device->pnp.bus_address = info->Address;
595
                device->flags.bus_address = 1;
596
            }
597
598
 
599
600
 
601
         * Some devices don't reliably have _HIDs & _CIDs, so add
602
         * synthetic HIDs to make sure drivers can find them.
603
         */
604
        if (acpi_is_video_device(device))
605
            acpi_add_id(device, ACPI_VIDEO_HID);
606
        else if (ACPI_SUCCESS(acpi_bay_match(device)))
607
            acpi_add_id(device, ACPI_BAY_HID);
608
        else if (ACPI_SUCCESS(acpi_dock_match(device)))
609
            acpi_add_id(device, ACPI_DOCK_HID);
610
        else if (!acpi_device_hid(device) &&
611
             ACPI_IS_ROOT_DEVICE(device->parent)) {
612
            acpi_add_id(device, ACPI_BUS_HID); /* \_SB, LNXSYBUS */
613
            strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
614
            strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
615
        }
616
617
 
618
    case ACPI_BUS_TYPE_POWER:
619
        acpi_add_id(device, ACPI_POWER_HID);
620
        break;
621
    case ACPI_BUS_TYPE_PROCESSOR:
622
        acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID);
623
        break;
624
    case ACPI_BUS_TYPE_THERMAL:
625
        acpi_add_id(device, ACPI_THERMAL_HID);
626
        break;
627
    case ACPI_BUS_TYPE_POWER_BUTTON:
628
        acpi_add_id(device, ACPI_BUTTON_HID_POWERF);
629
        break;
630
    case ACPI_BUS_TYPE_SLEEP_BUTTON:
631
        acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF);
632
        break;
633
    }
634
635
 
636
     * We build acpi_devices for some objects that don't have _HID or _CID,
637
     * e.g., PCI bridges and slots.  Drivers can't bind to these objects,
638
     * but we do use them indirectly by traversing the acpi_device tree.
639
     * This generic ID isn't useful for driver binding, but it provides
640
     * the useful property that "every acpi_device has an ID."
641
     */
642
    if (list_empty(&device->pnp.ids))
643
        acpi_add_id(device, "device");
644
}
645
646
 
647
 
648
{
649
    ACPI_STATUS status;
650
651
 
652
     * Context
653
     * -------
654
     * Attach this 'struct acpi_device' to the ACPI object.  This makes
655
     * resolutions from handle->device very efficient.  Fixed hardware
656
     * devices have no handles, so we skip them.
657
     */
658
    if (!device->handle)
659
        return 0;
660
661
 
662
                  acpi_bus_data_handler, device);
663
    if (ACPI_SUCCESS(status))
664
        return 0;
665
666
 
667
    return -ENODEV;
668
}
669
670
 
671
 
672
{
673
    int result;
674
    struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
675
    int found = 0;
676
677
 
678
     * Linkage
679
     * -------
680
     * Link this device to its parent and siblings.
681
     */
682
    INIT_LIST_HEAD(&device->children);
683
    INIT_LIST_HEAD(&device->node);
684
685
 
686
    if (!new_bus_id) {
687
        dbgprintf(KERN_ERR "Memory allocation error\n");
688
        return -ENOMEM;
689
    }
690
691
 
692
    /*
693
     * Find suitable bus_id and instance number in acpi_bus_id_list
694
     * If failed, create one and link it into acpi_bus_id_list
695
     */
696
    list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node)
697
    {
698
        if (!strcmp(acpi_device_bus_id->bus_id, acpi_device_hid(device)))
699
        {
700
            acpi_device_bus_id->instance_no++;
701
            found = 1;
702
            kfree(new_bus_id);
703
            break;
704
        }
705
    }
706
    if (!found)
707
    {
708
        acpi_device_bus_id = new_bus_id;
709
        strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device));
710
        acpi_device_bus_id->instance_no = 0;
711
        list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
712
    }
713
714
 
715
716
 
717
        list_add_tail(&device->node, &device->parent->children);
718
719
 
720
721
 
722
//    device->dev.release = &acpi_device_release;
723
//    result = device_register(&device->dev);
724
//    if (result) {
725
//        dev_err(&device->dev, "Error registering device\n");
726
//        goto end;
727
//    }
728
729
 
730
 
731
    return 0;
732
end:
733
    mutex_lock(&acpi_device_lock);
734
    if (device->parent)
735
        list_del(&device->node);
736
    mutex_unlock(&acpi_device_lock);
737
    return result;
738
}
739
740
 
741
 
742
 
743
                  ACPI_HANDLE handle, int type,
744
                  unsigned long long sta,
745
                  struct acpi_bus_ops *ops)
746
{
747
    int result;
748
    struct acpi_device *device;
749
    ACPI_BUFFER buffer = { ACPI_ALLOCATE_BUFFER, NULL };
750
751
 
752
    if (!device) {
753
        dbgprintf("%s: Memory allocation error\n", __FUNCTION__);
754
        return -ENOMEM;
755
    }
756
757
 
758
    device->device_type = type;
759
    device->handle = handle;
760
    device->parent = acpi_bus_get_parent(handle);
761
    device->bus_ops = *ops; /* workround for not call .start */
762
    STRUCT_TO_INT(device->status) = sta;
763
764
 
765
766
 
767
     * Flags
768
     * -----
769
     * Note that we only look for object handles -- cannot evaluate objects
770
     * until we know the device is present and properly initialized.
771
     */
772
    result = acpi_bus_get_flags(device);
773
    if (result)
774
        goto end;
775
776
 
777
     * Initialize Device
778
     * -----------------
779
     * TBD: Synch with Core's enumeration/initialization process.
780
     */
781
    acpi_device_set_id(device);
782
783
 
784
 
785
        goto end;
786
787
 
788
789
 
790
     * Bind _ADR-Based Devices when hot add
791
     */
792
//    if (device->flags.bus_address) {
793
//        if (device->parent && device->parent->ops.bind)
794
//            device->parent->ops.bind(device);
795
//    }
796
797
 
798
    if (!result) {
799
        AcpiGetName(handle, ACPI_FULL_PATHNAME, &buffer);
800
        dbgprintf("Adding [%s]\n", (char *)buffer.Pointer);
801
        kfree(buffer.Pointer);
802
        *child = device;
803
    };
804
    return result;
805
}
806
807
 
808
 
809
 
810
 
811
                      void *context, void **return_value)
812
{
813
    struct acpi_bus_ops *ops = context;
814
    int type;
815
    unsigned long long sta;
816
    struct acpi_device *device;
817
    ACPI_STATUS status;
818
    int result;
819
820
 
821
822
 
823
    {
824
        return AE_OK;
825
    };
826
827
 
828
        !(sta & ACPI_STA_DEVICE_FUNCTIONING))
829
    {
830
        return AE_CTRL_DEPTH;
831
    };
832
833
 
834
     * We may already have an acpi_device from a previous enumeration.  If
835
     * so, we needn't add it again, but we may still have to start it.
836
     */
837
    device = NULL;
838
    acpi_bus_get_device(handle, &device);
839
    if (ops->acpi_op_add && !device)
840
        acpi_add_single_object(&device, handle, type, sta, ops);
841
842
 
843
    {
844
        return AE_CTRL_DEPTH;
845
    };
846
/*
847
    if (ops->acpi_op_start && !(ops->acpi_op_add)) {
848
        status = acpi_start_single_object(device);
849
        if (ACPI_FAILURE(status))
850
            return AE_CTRL_DEPTH;
851
    }
852
*/
853
854
 
855
        *return_value = device;
856
857
 
858
}
859
860
 
861
 
862
 
863
             struct acpi_device **child)
864
{
865
    ACPI_STATUS status;
866
    void *device = NULL;
867
868
 
869
870
 
871
872
 
873
        AcpiWalkNamespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
874
                    acpi_bus_check_add, NULL, ops, &device);
875
876
 
877
        *child = device;
878
879
 
880
881
 
882
        return 0;
883
    else
884
        return -ENODEV;
885
}
886
887
 
888
 
889
 
890
{
891
    int err;
892
    struct acpi_bus_ops ops;
893
894
 
895
    ops.acpi_op_add = 1;
896
    ops.acpi_op_start = 1;
897
898
 
899
900
 
901
};
902
903
 
904
 
905
{
906
    IO_PIC  = 0,
907
    IO_APIC
908
};
909
910
 
911
{
912
    ACPI_OBJECT arg1;
913
    ACPI_OBJECT_LIST args;
914
    ACPI_STATUS as;
915
916
 
917
    arg1.Integer.Value = mode;
918
    args.Count = 1;
919
    args.Pointer = &arg1;
920
921
 
922
    /*
923
     * We can silently ignore failure as it may not be implemented, ACPI should
924
     * provide us with correct information anyway
925
     */
926
    if (ACPI_SUCCESS(as))
927
        dbgprintf("ACPI: machine set to %s mode\n", mode ? "APIC" : "PIC");
928
}
929
930
 
931
{
932
    struct acpi_device *child;
933
934
 
935
936
 
937
    {
938
        print_device_tree(child);
939
    };
940
};
941
942
 
1498 serge 943
{
944
    u32_t retval;
945
946
 
1500 serge 947
948
 
1498 serge 949
950
 
951
        return 0;
952
953
 
1625 serge 954
    {
955
        printf("Can't open /rd/1/drivers/acpi.log\nExit\n");
956
        return 0;
957
    }
958
959
 
1500 serge 960
    if (ACPI_FAILURE(status)) {
961
        dbgprintf("Unable to reallocate ACPI tables\n");
962
        goto err;
963
    }
964
1498 serge 965
 
1500 serge 966
    if (status != AE_OK) {
967
          dbgprintf("AcpiInitializeSubsystem failed (%s)\n",
968
                     AcpiFormatException(status));
969
          goto err;
970
    }
971
1498 serge 972
 
1500 serge 973
    if (status != AE_OK) {
974
          dbgprintf("AcpiInitializeTables failed (%s)\n",
975
                     AcpiFormatException(status));
976
          goto err;
977
    }
978
1498 serge 979
 
1500 serge 980
    if (status != AE_OK) {
981
          dbgprintf("AcpiLoadTables failed (%s)\n",
982
                     AcpiFormatException(status));
983
          goto err;
984
    }
985
1498 serge 986
 
1625 serge 987
1498 serge 988
 
1625 serge 989
    if (status != AE_OK) {
1498 serge 990
        dbgprintf("AcpiEnableSubsystem failed (%s)\n",
991
            AcpiFormatException(status));
992
        goto err;
993
    }
994
995
 
1625 serge 996
    if (ACPI_FAILURE (status))
1498 serge 997
    {
998
        dbgprintf("AcpiInitializeObjects failed (%s)\n",
999
            AcpiFormatException(status));
1000
        goto err;
1001
    }
1002
1003
 
1625 serge 1004
 
1005
1006
 
1007
    scan_devices();
1008
1009
 
1010
        bool retval = false;
1011
        u32_t bus, last_bus;
1012
1013
 
1014
            return retval;
1015
1016
 
1017
1018
 
1019
        {
1020
            u32_t dev;
1021
1022
 
1023
            {
1024
                u32_t fn;
1025
1026
 
1027
                {
1028
1029
 
1030
                    u32_t irq_bios, irq_acpi;
1031
                    u32_t irq_pin;
1032
                    u16_t pcicmd;
1033
                    u32_t tmp;
1034
1035
 
1036
1037
 
1038
1039
 
1040
                if (id == 0xffffffff || id == 0x00000000 ||
1041
                    id == 0x0000ffff || id == 0xffff0000)
1042
                    continue;
1043
1044
 
1045
                if (! pcicmd & PCI_COMMAND_IO)
1046
                    continue;
1047
1048
 
1049
1050
 
1051
                irq_pin  = (tmp >> 8) & 0xFF;
1052
1053
 
1054
1055
 
1056
1057
 
1058
                    dbgprintf("PCI: no ACPI IRQ routing for "
1059
                    "device %d.%d.%d INT%c\n",bus,dev,fn,'A'+irq_pin-1);
1060
1061
 
1062
                          "IRQ PIN %d BIOS IRQ %d ACPI IRQ %d\n",
1063
                          id & 0xFFFF, id>>16, bus, dev, fn, irq_pin, irq_bios, irq_acpi);
1064
                };
1065
            }
1066
        };
1067
    };
1068
#endif
1069
1070
 
1071
1072
 
1073
1074
 
1075
    ACPI_HANDLE bus_handle;
1076
    ACPI_HANDLE pci_root;
1077
1078
 
1079
    dbgprintf("system bus handle %x\n", bus_handle);
1080
1081
 
1082
    if (status != AE_OK) {
1083
          dbgprintf("AcpiGetHandle failed (%s)\n",
1084
                     AcpiFormatException(status));
1085
          goto err;
1086
    }
1087
1088
 
1089
                      get_device_by_hid_callback, NULL, NULL, NULL);
1498 serge 1090
*/
1625 serge 1091
1498 serge 1092
 
1093
1094
 
1625 serge 1095
                      get_device_by_hid_callback, NULL, NULL, NULL);
1096
1097
 
1498 serge 1098
    ACPI_HANDLE bus_handle;
1099
    ACPI_HANDLE pci_root;
1100
1101
 
1102
    dbgprintf("system bus handle %x\n", bus_handle);
1103
1104
 
1105
1106
 
1107
        dbgprintf("AcpiGetHandle failed (%s)\n",
1108
            AcpiFormatException(status));
1109
        goto err;
1110
    }
1111
1112
 
1113
1114
 
1115
1116
 
1117
    prt_buffer.Pointer = NULL;
1118
1119
 
1120
1121
 
1122
        dbgprintf("AcpiGetIrqRoutingTable failed (%s)\n",
1123
            AcpiFormatException(status));
1124
        goto err;
1125
    }
1126
1127
 
1128
1129
 
1130
 
1131
    ACPI_OBJECT_LIST arg_list = { 1, &arg };
1132
1133
 
1134
1135
 
1136
1137
 
1138
1139
 
1140
        dbgprintf("AcpiEvaluateObject failed (%s)\n",
1141
            AcpiFormatException(status));
1142
 //       goto err;
1143
    }
1144
1145
 
1146
 
1147
1148
 
1149
        dbgprintf("AcpiGetIrqRoutingTable failed (%s)\n",
1150
            AcpiFormatException(status));
1151
        goto err;
1152
    }
1153
1154
 
1155
1156
 
1157
    dbgprintf("bus 0 device 31 function 1 pin %d\n", pin-1);
1158
1159
 
1160
    dbgprintf("bus 0 device 31 function 2 pin %d\n", pin-1);
1161
1162
 
1163
    dbgprintf("bus 0 device 31 function 3 pin %d\n", pin-1);
1164
1165
 
1166
    dbgprintf("bus 0 device 31 function 4 pin %d\n", pin-1);
1167
1168
 
1169
    dbgprintf("bus 0 device 31 function 5 pin %d\n", pin-1);
1170
1171
 
1172
    dbgprintf("bus 0 device 31 function 6 pin %d\n", pin-1);
1173
1174
 
1175
    dbgprintf("bus 0 device 31 function 7 pin %d\n", pin-1);
1176
#endif
1177
1178
 
1179
1180
 
1181
1182
 
1183
1184
 
1625 serge 1185
 
1186
1187
 
1188
get_device_by_hid_callback(ACPI_HANDLE obj, u32_t depth, void* context,
1189
    void** retval)
1190
{
1191
    static u32_t counter = 0;
1192
    static char buff[256];
1193
1194
 
1195
1196
 
1197
1198
 
1199
1200
 
1201
1202
 
1203
    buffer.Pointer = buff;
1204
1205
 
1206
    if (status != AE_OK) {
1207
        return AE_CTRL_TERMINATE;
1208
    }
1209
1210
 
1211
1212
 
1213
1214
 
1215
1216
 
1217
    {
1218
        if (info->Valid & ACPI_VALID_HID)
1219
            dbgprintf (" HID: %s", info->HardwareId.String);
1220
1221
 
1222
1223
 
1224
    counter++;
1225
1226
 
1227
}
1228
1229
 
1230
{
1231
    ACPI_PCI_ROUTING_TABLE *entry;
1232
    char *prtptr;
1233
1234
 
1235
    if (prt == NULL || prt->Pointer == NULL)
1236
        return;
1237
1238
 
1239
    prtptr = prt->Pointer;
1240
    entry = (ACPI_PCI_ROUTING_TABLE *)prtptr;
1241
    while (entry->Length != 0)
1242
    {
1243
1244
 
1245
                  (u32_t)entry->Address);
1246
        dbgprintf("pin: %d  index: %d  source: %s\n",
1247
                   entry->Pin,
1248
                   entry->SourceIndex,
1249
                   entry->Source);
1250
1251
 
1252
        prtptr += entry->Length;
1253
        entry = (ACPI_PCI_ROUTING_TABLE *)prtptr;
1254
    }
1255
}
1256
1257
 
1258
 
1259
{
1260
//    assert(dev < PCI_MAX_DEVICES && pin < PCI_MAX_PINS);
1261
1262
 
1263
}
1264
1265
 
1266
{
1267
    ACPI_PCI_ROUTING_TABLE *tbl = (ACPI_PCI_ROUTING_TABLE *) context;
1268
1269
 
1270
    {
1271
        ACPI_RESOURCE_IRQ *irq;
1272
1273
 
1274
        add_irq(tbl->Address >> 16, tbl->Pin,
1275
                irq->Interrupts[tbl->SourceIndex]);
1276
    } else if (res->Type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ)
1277
    {
1278
        ACPI_RESOURCE_EXTENDED_IRQ *irq;
1279
1280
 
1281
                irq->Interrupts[tbl->SourceIndex]);
1282
    }
1283
1284
 
1285
}
1286
1287
 
1288
1289
 
1290
{
1291
    ACPI_STATUS status;
1292
    ACPI_BUFFER abuff;
1293
    ACPI_PCI_ROUTING_TABLE *tbl;
1294
1295
 
1296
    abuff.Pointer = buff;
1297
1298
 
1299
    if (ACPI_FAILURE(status)) {
1300
        return AE_OK;
1301
    }
1302
1303
 
1304
            tbl = (ACPI_PCI_ROUTING_TABLE *)
1305
            ((char *)tbl + tbl->Length))
1306
    {
1307
        ACPI_HANDLE src_handle;
1308
1309
 
1310
            add_irq(tbl->Address >> 16, tbl->Pin, tbl->SourceIndex);
1311
            continue;
1312
        }
1313
1314
 
1315
        if (ACPI_FAILURE(status)) {
1316
            printf("Failed AcpiGetHandle\n");
1317
            continue;
1318
        }
1319
        status = AcpiWalkResources(src_handle, METHOD_NAME__CRS,
1320
                get_irq_resource, tbl);
1321
        if (ACPI_FAILURE(status)) {
1322
            printf("Failed IRQ resource\n");
1323
            continue;
1324
        }
1325
    }
1326
1327
 
1328
}
1329
1330
 
1331
                UINT32 level,
1332
                void *context,
1333
                void **retval)
1334
{
1335
    int i;
1336
    static unsigned called;
1337
1338
 
1339
        dbgprintf("ACPI: Warning! Multi rooted PCI is not supported!\n");
1340
        return AE_OK;
1341
    }
1342
1343
 
1344
        irqtable[i] = -1;
1345
1346
 
1347
}
1348
1349
 
1350
                UINT32 level,
1351
                void *context,
1352
                void **retval)
1353
{
1354
    /* skip pci root when we get to it again */
1355
    if (handle == pci_root_handle)
1356
        return AE_OK;
1357
1358
 
1359
}
1360
1361
 
1362
{
1363
    ACPI_STATUS status;
1364
1365
 
1366
    status = AcpiGetDevices("PNP0A03", add_pci_root_dev, NULL, NULL);
1367
    if (status != AE_OK) {
1368
        dbgprintf("scan_devices failed (%s)\n",
1369
                   AcpiFormatException(status));
1370
          return;
1371
    }
1372
1373
 
1374
1375
 
1376
    status = AcpiGetDevices(NULL, add_pci_dev, NULL, NULL);
1377
//    assert(ACPI_SUCCESS(status));
1378
}
1379
1380
 
1381