OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [hotplug/] [acpiphp_glue.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * ACPI PCI HotPlug glue functions to ACPI CA subsystem
3
 *
4
 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
5
 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
6
 * Copyright (C) 2002,2003 NEC Corporation
7
 *
8
 * All rights reserved.
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or (at
13
 * your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful, but
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18
 * NON INFRINGEMENT.  See the GNU General Public License for more
19
 * details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
 *
25
 * Send feedback to <t-kochi@bq.jp.nec.com>
26
 *
27
 */
28
 
29
#include <linux/config.h>
30
#include <linux/kernel.h>
31
#include <linux/module.h>
32
#include <linux/pci.h>
33
#include <linux/smp_lock.h>
34
#include <linux/init.h>
35
#include <asm/semaphore.h>
36
 
37
#include "pci_hotplug.h"
38
#include "acpiphp.h"
39
 
40
static LIST_HEAD(bridge_list);
41
 
42
#define MY_NAME "acpiphp_glue"
43
 
44
static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
45
static void handle_hotplug_event_func (acpi_handle, u32, void *);
46
 
47
/*
48
 * initialization & terminatation routines
49
 */
50
 
51
/**
52
 * is_ejectable - determine if a slot is ejectable
53
 * @handle: handle to acpi namespace
54
 *
55
 * Ejectable slot should satisfy at least these conditions:
56
 *
57
 *  1. has _ADR method
58
 *  2. has _EJ0 method
59
 *
60
 * optionally
61
 *
62
 *  1. has _STA method
63
 *  2. has _PS0 method
64
 *  3. has _PS3 method
65
 *  4. ..
66
 *
67
 */
68
static int is_ejectable (acpi_handle handle)
69
{
70
        acpi_status status;
71
        acpi_handle tmp;
72
 
73
        status = acpi_get_handle(handle, "_ADR", &tmp);
74
        if (ACPI_FAILURE(status)) {
75
                return 0;
76
        }
77
 
78
        status = acpi_get_handle(handle, "_EJ0", &tmp);
79
        if (ACPI_FAILURE(status)) {
80
                return 0;
81
        }
82
 
83
        return 1;
84
}
85
 
86
 
87
/* callback routine to check the existence of ejectable slots */
88
static acpi_status
89
is_ejectable_slot (acpi_handle handle, u32 lvl, void *context, void **rv)
90
{
91
        int *count = (int *)context;
92
 
93
        if (is_ejectable(handle)) {
94
                (*count)++;
95
                /* only one ejectable slot is enough */
96
                return AE_CTRL_TERMINATE;
97
        } else {
98
                return AE_OK;
99
        }
100
}
101
 
102
 
103
/* callback routine to register each ACPI PCI slot object */
104
static acpi_status
105
register_slot (acpi_handle handle, u32 lvl, void *context, void **rv)
106
{
107
        struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context;
108
        struct acpiphp_slot *slot;
109
        struct acpiphp_func *newfunc;
110
        acpi_handle tmp;
111
        acpi_status status = AE_OK;
112
        unsigned long adr, sun;
113
        int device, function;
114
        static int num_slots = 0;        /* XXX if we support I/O node hotplug... */
115
 
116
        status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
117
 
118
        if (ACPI_FAILURE(status))
119
                return AE_OK;
120
 
121
        status = acpi_get_handle(handle, "_EJ0", &tmp);
122
 
123
        if (ACPI_FAILURE(status))
124
                return AE_OK;
125
 
126
        device = (adr >> 16) & 0xffff;
127
        function = adr & 0xffff;
128
 
129
        newfunc = kmalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
130
        if (!newfunc)
131
                return AE_NO_MEMORY;
132
        memset(newfunc, 0, sizeof(struct acpiphp_func));
133
 
134
        INIT_LIST_HEAD(&newfunc->sibling);
135
        newfunc->handle = handle;
136
        newfunc->function = function;
137
        newfunc->flags = FUNC_HAS_EJ0;
138
 
139
        if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp)))
140
                newfunc->flags |= FUNC_HAS_STA;
141
 
142
        if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS0", &tmp)))
143
                newfunc->flags |= FUNC_HAS_PS0;
144
 
145
        if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp)))
146
                newfunc->flags |= FUNC_HAS_PS3;
147
 
148
        status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
149
        if (ACPI_FAILURE(status))
150
                sun = -1;
151
 
152
        /* search for objects that share the same slot */
153
        for (slot = bridge->slots; slot; slot = slot->next)
154
                if (slot->device == device) {
155
                        if (slot->sun != sun)
156
                                warn("sibling found, but _SUN doesn't match!\n");
157
                        break;
158
                }
159
 
160
        if (!slot) {
161
                slot = kmalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
162
                if (!slot) {
163
                        kfree(newfunc);
164
                        return AE_NO_MEMORY;
165
                }
166
 
167
                memset(slot, 0, sizeof(struct acpiphp_slot));
168
                slot->bridge = bridge;
169
                slot->id = num_slots++;
170
                slot->device = device;
171
                slot->sun = sun;
172
                INIT_LIST_HEAD(&slot->funcs);
173
                init_MUTEX(&slot->crit_sect);
174
 
175
                slot->next = bridge->slots;
176
                bridge->slots = slot;
177
 
178
                bridge->nr_slots++;
179
 
180
                dbg("found ACPI PCI Hotplug slot at PCI %02x:%02x Slot:%d\n",
181
                    slot->bridge->bus, slot->device, slot->sun);
182
        }
183
 
184
        newfunc->slot = slot;
185
        list_add_tail(&newfunc->sibling, &slot->funcs);
186
 
187
        /* associate corresponding pci_dev */
188
        newfunc->pci_dev = pci_find_slot(bridge->bus,
189
                                         PCI_DEVFN(device, function));
190
        if (newfunc->pci_dev) {
191
                if (acpiphp_init_func_resource(newfunc) < 0) {
192
                        kfree(newfunc);
193
                        return AE_ERROR;
194
                }
195
                slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
196
        }
197
 
198
        /* install notify handler */
199
        status = acpi_install_notify_handler(handle,
200
                                             ACPI_SYSTEM_NOTIFY,
201
                                             handle_hotplug_event_func,
202
                                             newfunc);
203
 
204
        if (ACPI_FAILURE(status)) {
205
                err("failed to register interrupt notify handler\n");
206
                return status;
207
        }
208
 
209
        return AE_OK;
210
}
211
 
212
 
213
/* see if it's worth looking at this bridge */
214
static int detect_ejectable_slots (acpi_handle *bridge_handle)
215
{
216
        acpi_status status;
217
        int count;
218
 
219
        count = 0;
220
 
221
        /* only check slots defined directly below bridge object */
222
        status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, (u32)1,
223
                                     is_ejectable_slot, (void *)&count, NULL);
224
 
225
        return count;
226
}
227
 
228
 
229
/* decode ACPI _CRS data and convert into our internal resource list
230
 * TBD: _TRA, etc.
231
 */
232
static void
233
decode_acpi_resource (struct acpi_resource *resource, struct acpiphp_bridge *bridge)
234
{
235
        struct acpi_resource_address16 *address16_data;
236
        struct acpi_resource_address32 *address32_data;
237
        struct acpi_resource_address64 *address64_data;
238
        struct pci_resource *res;
239
 
240
        u32 resource_type, producer_consumer, address_length;
241
        u64 min_address_range, max_address_range;
242
        u16 cache_attribute = 0;
243
 
244
        int done = 0, found;
245
 
246
        /* shut up gcc */
247
        resource_type = producer_consumer = address_length = 0;
248
        min_address_range = max_address_range = 0;
249
 
250
        while (!done) {
251
                found = 0;
252
 
253
                switch (resource->id) {
254
                case ACPI_RSTYPE_ADDRESS16:
255
                        address16_data = (struct acpi_resource_address16 *)&resource->data;
256
                        resource_type = address16_data->resource_type;
257
                        producer_consumer = address16_data->producer_consumer;
258
                        min_address_range = address16_data->min_address_range;
259
                        max_address_range = address16_data->max_address_range;
260
                        address_length = address16_data->address_length;
261
                        if (resource_type == ACPI_MEMORY_RANGE)
262
                                cache_attribute = address16_data->attribute.memory.cache_attribute;
263
                        found = 1;
264
                        break;
265
 
266
                case ACPI_RSTYPE_ADDRESS32:
267
                        address32_data = (struct acpi_resource_address32 *)&resource->data;
268
                        resource_type = address32_data->resource_type;
269
                        producer_consumer = address32_data->producer_consumer;
270
                        min_address_range = address32_data->min_address_range;
271
                        max_address_range = address32_data->max_address_range;
272
                        address_length = address32_data->address_length;
273
                        if (resource_type == ACPI_MEMORY_RANGE)
274
                                cache_attribute = address32_data->attribute.memory.cache_attribute;
275
                        found = 1;
276
                        break;
277
 
278
                case ACPI_RSTYPE_ADDRESS64:
279
                        address64_data = (struct acpi_resource_address64 *)&resource->data;
280
                        resource_type = address64_data->resource_type;
281
                        producer_consumer = address64_data->producer_consumer;
282
                        min_address_range = address64_data->min_address_range;
283
                        max_address_range = address64_data->max_address_range;
284
                        address_length = address64_data->address_length;
285
                        if (resource_type == ACPI_MEMORY_RANGE)
286
                                cache_attribute = address64_data->attribute.memory.cache_attribute;
287
                        found = 1;
288
                        break;
289
 
290
                case ACPI_RSTYPE_END_TAG:
291
                        done = 1;
292
                        break;
293
 
294
                default:
295
                        /* ignore */
296
                        break;
297
                }
298
 
299
                resource = (struct acpi_resource *)((char*)resource + resource->length);
300
 
301
                if (found && producer_consumer == ACPI_PRODUCER && address_length > 0) {
302
                        switch (resource_type) {
303
                        case ACPI_MEMORY_RANGE:
304
                                if (cache_attribute == ACPI_PREFETCHABLE_MEMORY) {
305
                                        dbg("resource type: prefetchable memory 0x%x - 0x%x\n", (u32)min_address_range, (u32)max_address_range);
306
                                        res = acpiphp_make_resource(min_address_range,
307
                                                            address_length);
308
                                        if (!res) {
309
                                                err("out of memory\n");
310
                                                return;
311
                                        }
312
                                        res->next = bridge->p_mem_head;
313
                                        bridge->p_mem_head = res;
314
                                } else {
315
                                        dbg("resource type: memory 0x%x - 0x%x\n", (u32)min_address_range, (u32)max_address_range);
316
                                        res = acpiphp_make_resource(min_address_range,
317
                                                            address_length);
318
                                        if (!res) {
319
                                                err("out of memory\n");
320
                                                return;
321
                                        }
322
                                        res->next = bridge->mem_head;
323
                                        bridge->mem_head = res;
324
                                }
325
                                break;
326
                        case ACPI_IO_RANGE:
327
                                dbg("resource type: io 0x%x - 0x%x\n", (u32)min_address_range, (u32)max_address_range);
328
                                res = acpiphp_make_resource(min_address_range,
329
                                                    address_length);
330
                                if (!res) {
331
                                        err("out of memory\n");
332
                                        return;
333
                                }
334
                                res->next = bridge->io_head;
335
                                bridge->io_head = res;
336
                                break;
337
                        case ACPI_BUS_NUMBER_RANGE:
338
                                dbg("resource type: bus number %d - %d\n", (u32)min_address_range, (u32)max_address_range);
339
                                res = acpiphp_make_resource(min_address_range,
340
                                                    address_length);
341
                                if (!res) {
342
                                        err("out of memory\n");
343
                                        return;
344
                                }
345
                                res->next = bridge->bus_head;
346
                                bridge->bus_head = res;
347
                                break;
348
                        default:
349
                                /* invalid type */
350
                                break;
351
                        }
352
                }
353
        }
354
 
355
        acpiphp_resource_sort_and_combine(&bridge->io_head);
356
        acpiphp_resource_sort_and_combine(&bridge->mem_head);
357
        acpiphp_resource_sort_and_combine(&bridge->p_mem_head);
358
        acpiphp_resource_sort_and_combine(&bridge->bus_head);
359
 
360
        dbg("ACPI _CRS resource:\n");
361
        acpiphp_dump_resource(bridge);
362
}
363
 
364
 
365
/* find pci_bus structure associated to specific bus number */
366
static struct pci_bus *find_pci_bus(const struct list_head *list, int bus)
367
{
368
        const struct list_head *l;
369
 
370
        list_for_each (l, list) {
371
                struct pci_bus *b = pci_bus_b(l);
372
                if (b->number == bus)
373
                        return b;
374
 
375
                if (!list_empty(&b->children)) {
376
                        /* XXX recursive call */
377
                        b = find_pci_bus(&b->children, bus);
378
 
379
                        if (b)
380
                                return b;
381
                }
382
        }
383
 
384
        return NULL;
385
}
386
 
387
 
388
/* decode ACPI 2.0 _HPP hot plug parameters */
389
static void decode_hpp(struct acpiphp_bridge *bridge)
390
{
391
        acpi_status status;
392
#if ACPI_CA_VERSION < 0x20020201
393
        acpi_buffer buffer;
394
#else
395
        struct acpi_buffer buffer = { .length = ACPI_ALLOCATE_BUFFER,
396
                                      .pointer = NULL};
397
#endif
398
        union acpi_object *package;
399
        int i;
400
 
401
        /* default numbers */
402
        bridge->hpp.cache_line_size = 0x10;
403
        bridge->hpp.latency_timer = 0x40;
404
        bridge->hpp.enable_SERR = 0;
405
        bridge->hpp.enable_PERR = 0;
406
 
407
#if ACPI_CA_VERSION < 0x20020201
408
        buffer.length = 0;
409
        buffer.pointer = NULL;
410
 
411
        status = acpi_evaluate_object(bridge->handle, "_HPP", NULL, &buffer);
412
 
413
        if (status == AE_BUFFER_OVERFLOW) {
414
                buffer.pointer = kmalloc(buffer.length, GFP_KERNEL);
415
                if (!buffer.pointer)
416
                        return;
417
                status = acpi_evaluate_object(bridge->handle, "_HPP", NULL, &buffer);
418
        }
419
#else
420
        status = acpi_evaluate_object(bridge->handle, "_HPP", NULL, &buffer);
421
#endif
422
 
423
        if (ACPI_FAILURE(status)) {
424
                dbg("_HPP evaluation failed\n");
425
                return;
426
        }
427
 
428
        package = (union acpi_object *) buffer.pointer;
429
 
430
        if (!package || package->type != ACPI_TYPE_PACKAGE ||
431
            package->package.count != 4 || !package->package.elements) {
432
                err("invalid _HPP object; ignoring\n");
433
                goto err_exit;
434
        }
435
 
436
        for (i = 0; i < 4; i++) {
437
                if (package->package.elements[i].type != ACPI_TYPE_INTEGER) {
438
                        err("invalid _HPP parameter type; ignoring\n");
439
                        goto err_exit;
440
                }
441
        }
442
 
443
        bridge->hpp.cache_line_size = package->package.elements[0].integer.value;
444
        bridge->hpp.latency_timer = package->package.elements[1].integer.value;
445
        bridge->hpp.enable_SERR = package->package.elements[2].integer.value;
446
        bridge->hpp.enable_PERR = package->package.elements[3].integer.value;
447
 
448
        dbg("_HPP parameter = (%02x, %02x, %02x, %02x)\n",
449
            bridge->hpp.cache_line_size,
450
            bridge->hpp.latency_timer,
451
            bridge->hpp.enable_SERR,
452
            bridge->hpp.enable_PERR);
453
 
454
        bridge->flags |= BRIDGE_HAS_HPP;
455
 
456
 err_exit:
457
        kfree(buffer.pointer);
458
}
459
 
460
 
461
/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
462
static void init_bridge_misc (struct acpiphp_bridge *bridge)
463
{
464
        acpi_status status;
465
 
466
        /* decode ACPI 2.0 _HPP (hot plug parameters) */
467
        decode_hpp(bridge);
468
 
469
        /* subtract all resources already allocated */
470
        acpiphp_detect_pci_resource(bridge);
471
 
472
        /* register all slot objects under this bridge */
473
        status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
474
                                     register_slot, bridge, NULL);
475
 
476
        /* install notify handler */
477
        status = acpi_install_notify_handler(bridge->handle,
478
                                             ACPI_SYSTEM_NOTIFY,
479
                                             handle_hotplug_event_bridge,
480
                                             bridge);
481
 
482
        if (ACPI_FAILURE(status)) {
483
                err("failed to register interrupt notify handler\n");
484
        }
485
 
486
        list_add(&bridge->list, &bridge_list);
487
 
488
        dbg("Bridge resource:\n");
489
        acpiphp_dump_resource(bridge);
490
}
491
 
492
 
493
/* allocate and initialize host bridge data structure */
494
static void add_host_bridge (acpi_handle *handle, int seg, int bus)
495
{
496
        acpi_status status;
497
#if ACPI_CA_VERSION < 0x20020201
498
        acpi_buffer buffer;
499
#else
500
        struct acpi_buffer buffer = { .length = ACPI_ALLOCATE_BUFFER,
501
                                      .pointer = NULL};
502
#endif
503
        struct acpiphp_bridge *bridge;
504
 
505
        bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
506
        if (bridge == NULL)
507
                return;
508
 
509
        memset(bridge, 0, sizeof(struct acpiphp_bridge));
510
 
511
        bridge->type = BRIDGE_TYPE_HOST;
512
        bridge->handle = handle;
513
        bridge->seg = seg;
514
        bridge->bus = bus;
515
 
516
        bridge->pci_bus = find_pci_bus(&pci_root_buses, bus);
517
 
518
        bridge->res_lock = SPIN_LOCK_UNLOCKED;
519
 
520
        /* to be overridden when we decode _CRS */
521
        bridge->sub = bridge->bus;
522
 
523
        /* decode resources */
524
 
525
#if ACPI_CA_VERSION < 0x20020201
526
        buffer.length = 0;
527
        buffer.pointer = NULL;
528
 
529
        status = acpi_get_current_resources(handle, &buffer);
530
 
531
        if (status == AE_BUFFER_OVERFLOW) {
532
                buffer.pointer = kmalloc(buffer.length, GFP_KERNEL);
533
                if (!buffer.pointer)
534
                        return;
535
                status = acpi_get_current_resources(handle, &buffer);
536
        }
537
#else
538
        status = acpi_get_current_resources(handle, &buffer);
539
#endif
540
 
541
        if (ACPI_FAILURE(status)) {
542
                err("failed to decode bridge resources\n");
543
                kfree(bridge);
544
                return;
545
        }
546
 
547
        decode_acpi_resource(buffer.pointer, bridge);
548
        kfree(buffer.pointer);
549
 
550
        if (bridge->bus_head) {
551
                bridge->bus = bridge->bus_head->base;
552
                bridge->sub = bridge->bus_head->base + bridge->bus_head->length - 1;
553
        }
554
 
555
        init_bridge_misc(bridge);
556
}
557
 
558
 
559
/* allocate and initialize PCI-to-PCI bridge data structure */
560
static void add_p2p_bridge (acpi_handle *handle, int seg, int bus, int dev, int fn)
561
{
562
        struct acpiphp_bridge *bridge;
563
        u8 tmp8;
564
        u16 tmp16;
565
        u64 base64, limit64;
566
        u32 base, limit, base32u, limit32u;
567
 
568
        bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
569
        if (bridge == NULL) {
570
                err("out of memory\n");
571
                return;
572
        }
573
 
574
        memset(bridge, 0, sizeof(struct acpiphp_bridge));
575
 
576
        bridge->type = BRIDGE_TYPE_P2P;
577
        bridge->handle = handle;
578
        bridge->seg = seg;
579
 
580
        bridge->pci_dev = pci_find_slot(bus, PCI_DEVFN(dev, fn));
581
        if (!bridge->pci_dev) {
582
                err("Can't get pci_dev\n");
583
                kfree(bridge);
584
                return;
585
        }
586
 
587
        bridge->pci_bus = bridge->pci_dev->subordinate;
588
        if (!bridge->pci_bus) {
589
                err("This is not a PCI-to-PCI bridge!\n");
590
                kfree(bridge);
591
                return;
592
        }
593
 
594
        bridge->res_lock = SPIN_LOCK_UNLOCKED;
595
 
596
        bridge->bus = bridge->pci_bus->number;
597
        bridge->sub = bridge->pci_bus->subordinate;
598
 
599
        /*
600
         * decode resources under this P2P bridge
601
         */
602
 
603
        /* I/O resources */
604
        pci_read_config_byte(bridge->pci_dev, PCI_IO_BASE, &tmp8);
605
        base = tmp8;
606
        pci_read_config_byte(bridge->pci_dev, PCI_IO_LIMIT, &tmp8);
607
        limit = tmp8;
608
 
609
        switch (base & PCI_IO_RANGE_TYPE_MASK) {
610
        case PCI_IO_RANGE_TYPE_16:
611
                base = (base << 8) & 0xf000;
612
                limit = ((limit << 8) & 0xf000) + 0xfff;
613
                bridge->io_head = acpiphp_make_resource((u64)base, limit - base + 1);
614
                if (!bridge->io_head) {
615
                        err("out of memory\n");
616
                        kfree(bridge);
617
                        return;
618
                }
619
                dbg("16bit I/O range: %04x-%04x\n",
620
                    (u32)bridge->io_head->base,
621
                    (u32)(bridge->io_head->base + bridge->io_head->length - 1));
622
                break;
623
        case PCI_IO_RANGE_TYPE_32:
624
                pci_read_config_word(bridge->pci_dev, PCI_IO_BASE_UPPER16, &tmp16);
625
                base = ((u32)tmp16 << 16) | ((base << 8) & 0xf000);
626
                pci_read_config_word(bridge->pci_dev, PCI_IO_LIMIT_UPPER16, &tmp16);
627
                limit = (((u32)tmp16 << 16) | ((limit << 8) & 0xf000)) + 0xfff;
628
                bridge->io_head = acpiphp_make_resource((u64)base, limit - base + 1);
629
                if (!bridge->io_head) {
630
                        err("out of memory\n");
631
                        kfree(bridge);
632
                        return;
633
                }
634
                dbg("32bit I/O range: %08x-%08x\n",
635
                    (u32)bridge->io_head->base,
636
                    (u32)(bridge->io_head->base + bridge->io_head->length - 1));
637
                break;
638
        case 0x0f:
639
                dbg("I/O space unsupported\n");
640
                break;
641
        default:
642
                warn("Unknown I/O range type\n");
643
        }
644
 
645
        /* Memory resources (mandatory for P2P bridge) */
646
        pci_read_config_word(bridge->pci_dev, PCI_MEMORY_BASE, &tmp16);
647
        base = (tmp16 & 0xfff0) << 16;
648
        pci_read_config_word(bridge->pci_dev, PCI_MEMORY_LIMIT, &tmp16);
649
        limit = ((tmp16 & 0xfff0) << 16) | 0xfffff;
650
        bridge->mem_head = acpiphp_make_resource((u64)base, limit - base + 1);
651
        if (!bridge->mem_head) {
652
                err("out of memory\n");
653
                kfree(bridge);
654
                return;
655
        }
656
        dbg("32bit Memory range: %08x-%08x\n",
657
            (u32)bridge->mem_head->base,
658
            (u32)(bridge->mem_head->base + bridge->mem_head->length-1));
659
 
660
        /* Prefetchable Memory resources (optional) */
661
        pci_read_config_word(bridge->pci_dev, PCI_PREF_MEMORY_BASE, &tmp16);
662
        base = tmp16;
663
        pci_read_config_word(bridge->pci_dev, PCI_PREF_MEMORY_LIMIT, &tmp16);
664
        limit = tmp16;
665
 
666
        switch (base & PCI_MEMORY_RANGE_TYPE_MASK) {
667
        case PCI_PREF_RANGE_TYPE_32:
668
                base = (base & 0xfff0) << 16;
669
                limit = ((limit & 0xfff0) << 16) | 0xfffff;
670
                bridge->p_mem_head = acpiphp_make_resource((u64)base, limit - base + 1);
671
                if (!bridge->p_mem_head) {
672
                        err("out of memory\n");
673
                        kfree(bridge);
674
                        return;
675
                }
676
                dbg("32bit Prefetchable memory range: %08x-%08x\n",
677
                    (u32)bridge->p_mem_head->base,
678
                    (u32)(bridge->p_mem_head->base + bridge->p_mem_head->length - 1));
679
                break;
680
        case PCI_PREF_RANGE_TYPE_64:
681
                pci_read_config_dword(bridge->pci_dev, PCI_PREF_BASE_UPPER32, &base32u);
682
                pci_read_config_dword(bridge->pci_dev, PCI_PREF_LIMIT_UPPER32, &limit32u);
683
                base64 = ((u64)base32u << 32) | ((base & 0xfff0) << 16);
684
                limit64 = (((u64)limit32u << 32) | ((limit & 0xfff0) << 16)) + 0xfffff;
685
 
686
                bridge->p_mem_head = acpiphp_make_resource(base64, limit64 - base64 + 1);
687
                if (!bridge->p_mem_head) {
688
                        err("out of memory\n");
689
                        kfree(bridge);
690
                        return;
691
                }
692
                dbg("64bit Prefetchable memory range: %08x%08x-%08x%08x\n",
693
                    (u32)(bridge->p_mem_head->base >> 32),
694
                    (u32)(bridge->p_mem_head->base & 0xffffffff),
695
                    (u32)((bridge->p_mem_head->base + bridge->p_mem_head->length - 1) >> 32),
696
                    (u32)((bridge->p_mem_head->base + bridge->p_mem_head->length - 1) & 0xffffffff));
697
                break;
698
        case 0x0f:
699
                break;
700
        default:
701
                warn("Unknown prefetchale memory type\n");
702
        }
703
 
704
        init_bridge_misc(bridge);
705
}
706
 
707
 
708
/* callback routine to find P2P bridges */
709
static acpi_status
710
find_p2p_bridge (acpi_handle handle, u32 lvl, void *context, void **rv)
711
{
712
        acpi_status status;
713
        acpi_handle dummy_handle;
714
        unsigned long *segbus = context;
715
        unsigned long tmp;
716
        int seg, bus, device, function;
717
        struct pci_dev *dev;
718
 
719
        /* get PCI address */
720
        seg = (*segbus >> 8) & 0xff;
721
        bus = *segbus & 0xff;
722
 
723
        status = acpi_get_handle(handle, "_ADR", &dummy_handle);
724
        if (ACPI_FAILURE(status))
725
                return AE_OK;           /* continue */
726
 
727
        status = acpi_evaluate_integer(handle, "_ADR", NULL, &tmp);
728
        if (ACPI_FAILURE(status)) {
729
                dbg("%s: _ADR evaluation failure\n", __FUNCTION__);
730
                return AE_OK;
731
        }
732
 
733
        device = (tmp >> 16) & 0xffff;
734
        function = tmp & 0xffff;
735
 
736
        dev = pci_find_slot(bus, PCI_DEVFN(device, function));
737
 
738
        if (!dev)
739
                return AE_OK;
740
 
741
        if (!dev->subordinate)
742
                return AE_OK;
743
 
744
        /* check if this bridge has ejectable slots */
745
        if (detect_ejectable_slots(handle) > 0) {
746
                dbg("found PCI-to-PCI bridge at PCI %s\n", dev->slot_name);
747
                add_p2p_bridge(handle, seg, bus, device, function);
748
        }
749
 
750
        return AE_OK;
751
}
752
 
753
 
754
/* find hot-pluggable slots, and then find P2P bridge */
755
static int add_bridge (acpi_handle handle)
756
{
757
        acpi_status status;
758
        unsigned long tmp;
759
        int seg, bus;
760
        acpi_handle dummy_handle;
761
 
762
        /* if the bridge doesn't have _STA, we assume it is always there */
763
        status = acpi_get_handle(handle, "_STA", &dummy_handle);
764
        if (ACPI_SUCCESS(status)) {
765
                status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp);
766
                if (ACPI_FAILURE(status)) {
767
                        dbg("%s: _STA evaluation failure\n", __FUNCTION__);
768
                        return 0;
769
                }
770
                if ((tmp & ACPI_STA_FUNCTIONING) == 0)
771
                        /* don't register this object */
772
                        return 0;
773
        }
774
 
775
        /* get PCI segment number */
776
        status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp);
777
 
778
        seg = ACPI_SUCCESS(status) ? tmp : 0;
779
 
780
        /* get PCI bus number */
781
        status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp);
782
 
783
        if (ACPI_SUCCESS(status)) {
784
                bus = tmp;
785
        } else {
786
                warn("can't get bus number, assuming 0\n");
787
                bus = 0;
788
        }
789
 
790
        /* check if this bridge has ejectable slots */
791
        if (detect_ejectable_slots(handle) > 0) {
792
                dbg("found PCI host-bus bridge with hot-pluggable slots\n");
793
                add_host_bridge(handle, seg, bus);
794
                return 0;
795
        }
796
 
797
        tmp = seg << 8 | bus;
798
 
799
        /* search P2P bridges under this host bridge */
800
        status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
801
                                     find_p2p_bridge, &tmp, NULL);
802
 
803
        if (ACPI_FAILURE(status))
804
                warn("find_p2p_bridge faied (error code = 0x%x)\n",status);
805
 
806
        return 0;
807
}
808
 
809
 
810
static void remove_bridge (acpi_handle handle)
811
{
812
        /* No-op for now .. */
813
}
814
 
815
static int power_on_slot (struct acpiphp_slot *slot)
816
{
817
        acpi_status status;
818
        struct acpiphp_func *func;
819
        struct list_head *l;
820
        int retval = 0;
821
 
822
        /* is this already enabled? */
823
        if (slot->flags & SLOT_POWEREDON)
824
                goto err_exit;
825
 
826
        list_for_each (l, &slot->funcs) {
827
                func = list_entry(l, struct acpiphp_func, sibling);
828
 
829
                if (func->flags & FUNC_HAS_PS0) {
830
                        dbg("%s: executing _PS0 on %s\n", __FUNCTION__,
831
                            func->pci_dev->slot_name);
832
                        status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);
833
                        if (ACPI_FAILURE(status)) {
834
                                warn("%s: _PS0 failed\n", __FUNCTION__);
835
                                retval = -1;
836
                                goto err_exit;
837
                        }
838
                }
839
        }
840
 
841
        /* TBD: evaluate _STA to check if the slot is enabled */
842
 
843
        slot->flags |= SLOT_POWEREDON;
844
 
845
 err_exit:
846
        return retval;
847
}
848
 
849
 
850
static int power_off_slot (struct acpiphp_slot *slot)
851
{
852
        acpi_status status;
853
        struct acpiphp_func *func;
854
        struct list_head *l;
855
        struct acpi_object_list arg_list;
856
        union acpi_object arg;
857
 
858
        int retval = 0;
859
 
860
        /* is this already enabled? */
861
        if ((slot->flags & SLOT_POWEREDON) == 0)
862
                goto err_exit;
863
 
864
        list_for_each (l, &slot->funcs) {
865
                func = list_entry(l, struct acpiphp_func, sibling);
866
 
867
                if (func->flags & (FUNC_HAS_PS3 | FUNC_EXISTS)) {
868
                        status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
869
                        if (ACPI_FAILURE(status)) {
870
                                warn("%s: _PS3 failed\n", __FUNCTION__);
871
                                retval = -1;
872
                                goto err_exit;
873
                        }
874
                }
875
        }
876
 
877
        list_for_each (l, &slot->funcs) {
878
                func = list_entry(l, struct acpiphp_func, sibling);
879
 
880
                /* We don't want to call _EJ0 on non-existing functions. */
881
                if (func->flags & (FUNC_HAS_EJ0 | FUNC_EXISTS)) {
882
                        /* _EJ0 method take one argument */
883
                        arg_list.count = 1;
884
                        arg_list.pointer = &arg;
885
                        arg.type = ACPI_TYPE_INTEGER;
886
                        arg.integer.value = 1;
887
 
888
                        status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
889
                        if (ACPI_FAILURE(status)) {
890
                                warn("%s: _EJ0 failed\n", __FUNCTION__);
891
                                retval = -1;
892
                                goto err_exit;
893
                        }
894
                        func->flags &= (~FUNC_EXISTS);
895
                }
896
        }
897
 
898
        /* TBD: evaluate _STA to check if the slot is disabled */
899
 
900
        slot->flags &= (~SLOT_POWEREDON);
901
 
902
 err_exit:
903
        return retval;
904
}
905
 
906
 
907
/**
908
 * enable_device - enable, configure a slot
909
 * @slot: slot to be enabled
910
 *
911
 * This function should be called per *physical slot*,
912
 * not per each slot object in ACPI namespace.
913
 *
914
 */
915
static int enable_device (struct acpiphp_slot *slot)
916
{
917
        u8 bus;
918
        struct pci_dev dev0, *dev;
919
        struct pci_bus *child;
920
        struct list_head *l;
921
        struct acpiphp_func *func;
922
        int retval = 0;
923
 
924
        if (slot->flags & SLOT_ENABLED)
925
                goto err_exit;
926
 
927
        /* sanity check: dev should be NULL when hot-plugged in */
928
        dev = pci_find_slot(slot->bridge->bus, PCI_DEVFN(slot->device, 0));
929
        if (dev) {
930
                /* This case shouldn't happen */
931
                err("pci_dev structure already exists.\n");
932
                retval = -1;
933
                goto err_exit;
934
        }
935
 
936
        /* allocate resources to device */
937
        retval = acpiphp_configure_slot(slot);
938
        if (retval)
939
                goto err_exit;
940
 
941
        memset(&dev0, 0, sizeof (struct pci_dev));
942
 
943
        dev0.bus = slot->bridge->pci_bus;
944
        dev0.devfn = PCI_DEVFN(slot->device, 0);
945
        dev0.sysdata = dev0.bus->sysdata;
946
 
947
        /* returned `dev' is the *first function* only! */
948
        dev = pci_scan_slot (&dev0);
949
 
950
        if (!dev) {
951
                err("No new device found\n");
952
                retval = -1;
953
                goto err_exit;
954
        }
955
 
956
        if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
957
                pci_read_config_byte(dev, PCI_SECONDARY_BUS, &bus);
958
                child = (struct pci_bus*) pci_add_new_bus(dev->bus, dev, bus);
959
                pci_do_scan_bus(child);
960
        }
961
 
962
        /* associate pci_dev to our representation */
963
        list_for_each (l, &slot->funcs) {
964
                func = list_entry(l, struct acpiphp_func, sibling);
965
 
966
                func->pci_dev = pci_find_slot(slot->bridge->bus,
967
                                              PCI_DEVFN(slot->device,
968
                                                        func->function));
969
                if (!func->pci_dev)
970
                        continue;
971
 
972
                /* configure device */
973
                retval = acpiphp_configure_function(func);
974
                if (retval)
975
                        goto err_exit;
976
 
977
                func->flags |= FUNC_EXISTS;
978
        }
979
 
980
        slot->flags |= SLOT_ENABLED;
981
 
982
        dbg("Available resources:\n");
983
        acpiphp_dump_resource(slot->bridge);
984
 
985
 err_exit:
986
        return retval;
987
}
988
 
989
 
990
/**
991
 * disable_device - disable a slot
992
 */
993
static int disable_device (struct acpiphp_slot *slot)
994
{
995
        int retval = 0;
996
        struct acpiphp_func *func;
997
        struct list_head *l;
998
 
999
        /* is this slot already disabled? */
1000
        if (!(slot->flags & SLOT_ENABLED))
1001
                goto err_exit;
1002
 
1003
        list_for_each (l, &slot->funcs) {
1004
                func = list_entry(l, struct acpiphp_func, sibling);
1005
 
1006
                if (func->pci_dev) {
1007
                        if (acpiphp_unconfigure_function(func) == 0) {
1008
                                func->pci_dev = NULL;
1009
                        } else {
1010
                                err("failed to unconfigure device\n");
1011
                                retval = -1;
1012
                                goto err_exit;
1013
                        }
1014
                }
1015
        }
1016
 
1017
        slot->flags &= (~SLOT_ENABLED);
1018
 
1019
 err_exit:
1020
        return retval;
1021
}
1022
 
1023
 
1024
/**
1025
 * get_slot_status - get ACPI slot status
1026
 *
1027
 * if a slot has _STA for each function and if any one of them
1028
 * returned non-zero status, return it
1029
 *
1030
 * if a slot doesn't have _STA and if any one of its functions'
1031
 * configuration space is configured, return 0x0f as a _STA
1032
 *
1033
 * otherwise return 0
1034
 */
1035
static unsigned int get_slot_status (struct acpiphp_slot *slot)
1036
{
1037
        acpi_status status;
1038
        unsigned long sta = 0;
1039
        u32 dvid;
1040
        struct list_head *l;
1041
        struct acpiphp_func *func;
1042
 
1043
        list_for_each (l, &slot->funcs) {
1044
                func = list_entry(l, struct acpiphp_func, sibling);
1045
 
1046
                if (func->flags & FUNC_HAS_STA) {
1047
                        status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);
1048
                        if (ACPI_SUCCESS(status) && sta)
1049
                                break;
1050
                } else {
1051
                        pci_bus_read_config_dword(slot->bridge->pci_bus,
1052
                                        PCI_DEVFN(slot->device, func->function),
1053
                                        PCI_VENDOR_ID, &dvid);
1054
                        if (dvid != 0xffffffff) {
1055
                                sta = ACPI_STA_ALL;
1056
                                break;
1057
                        }
1058
                }
1059
        }
1060
 
1061
        return (unsigned int)sta;
1062
}
1063
 
1064
 
1065
/*
1066
 * ACPI event handlers
1067
 */
1068
 
1069
/**
1070
 * handle_hotplug_event_bridge - handle ACPI event on bridges
1071
 *
1072
 * @handle: Notify()'ed acpi_handle
1073
 * @type: Notify code
1074
 * @context: pointer to acpiphp_bridge structure
1075
 *
1076
 * handles ACPI event notification on {host,p2p} bridges
1077
 *
1078
 */
1079
static void handle_hotplug_event_bridge (acpi_handle handle, u32 type, void *context)
1080
{
1081
        struct acpiphp_bridge *bridge;
1082
        char objname[64];
1083
        struct acpi_buffer buffer = { .length = sizeof(objname),
1084
                                      .pointer = objname };
1085
 
1086
        bridge = (struct acpiphp_bridge *)context;
1087
 
1088
        acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1089
 
1090
        switch (type) {
1091
        case ACPI_NOTIFY_BUS_CHECK:
1092
                /* bus re-enumerate */
1093
                dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);
1094
                acpiphp_check_bridge(bridge);
1095
                break;
1096
 
1097
        case ACPI_NOTIFY_DEVICE_CHECK:
1098
                /* device check */
1099
                dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);
1100
                acpiphp_check_bridge(bridge);
1101
                break;
1102
 
1103
        case ACPI_NOTIFY_DEVICE_WAKE:
1104
                /* wake event */
1105
                dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);
1106
                break;
1107
 
1108
        case ACPI_NOTIFY_EJECT_REQUEST:
1109
                /* request device eject */
1110
                dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
1111
                break;
1112
 
1113
        default:
1114
                warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
1115
                break;
1116
        }
1117
}
1118
 
1119
 
1120
/**
1121
 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1122
 *
1123
 * @handle: Notify()'ed acpi_handle
1124
 * @type: Notify code
1125
 * @context: pointer to acpiphp_func structure
1126
 *
1127
 * handles ACPI event notification on slots
1128
 *
1129
 */
1130
static void handle_hotplug_event_func (acpi_handle handle, u32 type, void *context)
1131
{
1132
        struct acpiphp_func *func;
1133
        char objname[64];
1134
        struct acpi_buffer buffer = { .length = sizeof(objname),
1135
                                      .pointer = objname };
1136
 
1137
        acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1138
 
1139
        func = (struct acpiphp_func *)context;
1140
 
1141
        switch (type) {
1142
        case ACPI_NOTIFY_BUS_CHECK:
1143
                /* bus re-enumerate */
1144
                dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);
1145
                acpiphp_enable_slot(func->slot);
1146
                break;
1147
 
1148
        case ACPI_NOTIFY_DEVICE_CHECK:
1149
                /* device check : re-enumerate from parent bus */
1150
                dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);
1151
                acpiphp_check_bridge(func->slot->bridge);
1152
                break;
1153
 
1154
        case ACPI_NOTIFY_DEVICE_WAKE:
1155
                /* wake event */
1156
                dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);
1157
                break;
1158
 
1159
        case ACPI_NOTIFY_EJECT_REQUEST:
1160
                /* request device eject */
1161
                dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
1162
                acpiphp_disable_slot(func->slot);
1163
                break;
1164
 
1165
        default:
1166
                warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
1167
                break;
1168
        }
1169
}
1170
 
1171
 
1172
static struct acpi_pci_driver acpi_pci_hp_driver = {
1173
        .add =          add_bridge,
1174
        .remove =       remove_bridge,
1175
};
1176
 
1177
/**
1178
 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1179
 *
1180
 */
1181
int acpiphp_glue_init (void)
1182
{
1183
        int num;
1184
 
1185
        if (list_empty(&pci_root_buses))
1186
                return -1;
1187
 
1188
        num = acpi_pci_register_driver(&acpi_pci_hp_driver);
1189
 
1190
        if (num <= 0)
1191
                return -1;
1192
 
1193
        return 0;
1194
}
1195
 
1196
 
1197
/**
1198
 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
1199
 *
1200
 * This function frees all data allocated in acpiphp_glue_init()
1201
 */
1202
void acpiphp_glue_exit (void)
1203
{
1204
        struct list_head *l1, *l2, *n1, *n2;
1205
        struct acpiphp_bridge *bridge;
1206
        struct acpiphp_slot *slot, *next;
1207
        struct acpiphp_func *func;
1208
        acpi_status status;
1209
 
1210
        list_for_each_safe (l1, n1, &bridge_list) {
1211
                bridge = (struct acpiphp_bridge *)l1;
1212
                slot = bridge->slots;
1213
                while (slot) {
1214
                        next = slot->next;
1215
                        list_for_each_safe (l2, n2, &slot->funcs) {
1216
                                func = list_entry(l2, struct acpiphp_func, sibling);
1217
                                acpiphp_free_resource(&func->io_head);
1218
                                acpiphp_free_resource(&func->mem_head);
1219
                                acpiphp_free_resource(&func->p_mem_head);
1220
                                acpiphp_free_resource(&func->bus_head);
1221
                                status = acpi_remove_notify_handler(func->handle,
1222
                                                                    ACPI_SYSTEM_NOTIFY,
1223
                                                                    handle_hotplug_event_func);
1224
                                if (ACPI_FAILURE(status))
1225
                                        err("failed to remove notify handler\n");
1226
                                kfree(func);
1227
                        }
1228
                        kfree(slot);
1229
                        slot = next;
1230
                }
1231
                status = acpi_remove_notify_handler(bridge->handle, ACPI_SYSTEM_NOTIFY,
1232
                                                    handle_hotplug_event_bridge);
1233
                if (ACPI_FAILURE(status))
1234
                        err("failed to remove notify handler\n");
1235
 
1236
                acpiphp_free_resource(&bridge->io_head);
1237
                acpiphp_free_resource(&bridge->mem_head);
1238
                acpiphp_free_resource(&bridge->p_mem_head);
1239
                acpiphp_free_resource(&bridge->bus_head);
1240
 
1241
                kfree(bridge);
1242
        }
1243
}
1244
 
1245
 
1246
/**
1247
 * acpiphp_get_num_slots - count number of slots in a system
1248
 */
1249
int acpiphp_get_num_slots (void)
1250
{
1251
        struct list_head *node;
1252
        struct acpiphp_bridge *bridge;
1253
        int num_slots;
1254
 
1255
        num_slots = 0;
1256
 
1257
        list_for_each (node, &bridge_list) {
1258
                bridge = (struct acpiphp_bridge *)node;
1259
                dbg("Bus%d %dslot(s)\n", bridge->bus, bridge->nr_slots);
1260
                num_slots += bridge->nr_slots;
1261
        }
1262
 
1263
        dbg("Total %dslots\n", num_slots);
1264
        return num_slots;
1265
}
1266
 
1267
 
1268
/**
1269
 * acpiphp_for_each_slot - call function for each slot
1270
 * @fn: callback function
1271
 * @data: context to be passed to callback function
1272
 *
1273
 */
1274
int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
1275
{
1276
        struct list_head *node;
1277
        struct acpiphp_bridge *bridge;
1278
        struct acpiphp_slot *slot;
1279
        int retval = 0;
1280
 
1281
        list_for_each (node, &bridge_list) {
1282
                bridge = (struct acpiphp_bridge *)node;
1283
                for (slot = bridge->slots; slot; slot = slot->next) {
1284
                        retval = fn(slot, data);
1285
                        if (!retval)
1286
                                goto err_exit;
1287
                }
1288
        }
1289
 
1290
 err_exit:
1291
        return retval;
1292
}
1293
 
1294
 
1295
/* search matching slot from id  */
1296
struct acpiphp_slot *get_slot_from_id (int id)
1297
{
1298
        struct list_head *node;
1299
        struct acpiphp_bridge *bridge;
1300
        struct acpiphp_slot *slot;
1301
 
1302
        list_for_each (node, &bridge_list) {
1303
                bridge = (struct acpiphp_bridge *)node;
1304
                for (slot = bridge->slots; slot; slot = slot->next)
1305
                        if (slot->id == id)
1306
                                return slot;
1307
        }
1308
 
1309
        /* should never happen! */
1310
        err("%s: no object for id %d\n",__FUNCTION__, id);
1311
        return 0;
1312
}
1313
 
1314
 
1315
/**
1316
 * acpiphp_enable_slot - power on slot
1317
 */
1318
int acpiphp_enable_slot (struct acpiphp_slot *slot)
1319
{
1320
        int retval;
1321
 
1322
        down(&slot->crit_sect);
1323
 
1324
        /* wake up all functions */
1325
        retval = power_on_slot(slot);
1326
        if (retval)
1327
                goto err_exit;
1328
 
1329
        if (get_slot_status(slot) == ACPI_STA_ALL)
1330
                /* configure all functions */
1331
                retval = enable_device(slot);
1332
 
1333
 err_exit:
1334
        up(&slot->crit_sect);
1335
        return retval;
1336
}
1337
 
1338
 
1339
/**
1340
 * acpiphp_disable_slot - power off slot
1341
 */
1342
int acpiphp_disable_slot (struct acpiphp_slot *slot)
1343
{
1344
        int retval = 0;
1345
 
1346
        down(&slot->crit_sect);
1347
 
1348
        /* unconfigure all functions */
1349
        retval = disable_device(slot);
1350
        if (retval)
1351
                goto err_exit;
1352
 
1353
        /* power off all functions */
1354
        retval = power_off_slot(slot);
1355
        if (retval)
1356
                goto err_exit;
1357
 
1358
        acpiphp_resource_sort_and_combine(&slot->bridge->io_head);
1359
        acpiphp_resource_sort_and_combine(&slot->bridge->mem_head);
1360
        acpiphp_resource_sort_and_combine(&slot->bridge->p_mem_head);
1361
        acpiphp_resource_sort_and_combine(&slot->bridge->bus_head);
1362
        dbg("Available resources:\n");
1363
        acpiphp_dump_resource(slot->bridge);
1364
 
1365
 err_exit:
1366
        up(&slot->crit_sect);
1367
        return retval;
1368
}
1369
 
1370
 
1371
/**
1372
 * acpiphp_check_bridge - re-enumerate devices
1373
 */
1374
int acpiphp_check_bridge (struct acpiphp_bridge *bridge)
1375
{
1376
        struct acpiphp_slot *slot;
1377
        unsigned int sta;
1378
        int retval = 0;
1379
        int enabled, disabled;
1380
 
1381
        enabled = disabled = 0;
1382
 
1383
        for (slot = bridge->slots; slot; slot = slot->next) {
1384
                sta = get_slot_status(slot);
1385
                if (slot->flags & SLOT_ENABLED) {
1386
                        /* if enabled but not present, disable */
1387
                        if (sta != ACPI_STA_ALL) {
1388
                                retval = acpiphp_disable_slot(slot);
1389
                                if (retval) {
1390
                                        err("Error occurred in enabling\n");
1391
                                        up(&slot->crit_sect);
1392
                                        goto err_exit;
1393
                                }
1394
                                enabled++;
1395
                        }
1396
                } else {
1397
                        /* if disabled but present, enable */
1398
                        if (sta == ACPI_STA_ALL) {
1399
                                retval = acpiphp_enable_slot(slot);
1400
                                if (retval) {
1401
                                        err("Error occurred in enabling\n");
1402
                                        up(&slot->crit_sect);
1403
                                        goto err_exit;
1404
                                }
1405
                                disabled++;
1406
                        }
1407
                }
1408
        }
1409
 
1410
        dbg("%s: %d enabled, %d disabled\n", __FUNCTION__, enabled, disabled);
1411
 
1412
 err_exit:
1413
        return retval;
1414
}
1415
 
1416
 
1417
/*
1418
 * slot enabled:  1
1419
 * slot disabled: 0
1420
 */
1421
u8 acpiphp_get_power_status (struct acpiphp_slot *slot)
1422
{
1423
        unsigned int sta;
1424
 
1425
        sta = get_slot_status(slot);
1426
 
1427
        return (sta & ACPI_STA_ENABLED) ? 1 : 0;
1428
}
1429
 
1430
 
1431
/*
1432
 * attention LED ON: 1
1433
 *              OFF: 0
1434
 *
1435
 * TBD
1436
 * no direct attention led status information via ACPI
1437
 *
1438
 */
1439
u8 acpiphp_get_attention_status (struct acpiphp_slot *slot)
1440
{
1441
        return 0;
1442
}
1443
 
1444
 
1445
/*
1446
 * latch closed:  1
1447
 * latch   open:  0
1448
 */
1449
u8 acpiphp_get_latch_status (struct acpiphp_slot *slot)
1450
{
1451
        unsigned int sta;
1452
 
1453
        sta = get_slot_status(slot);
1454
 
1455
        return (sta & ACPI_STA_SHOW_IN_UI) ? 1 : 0;
1456
}
1457
 
1458
 
1459
/*
1460
 * adapter presence : 1
1461
 *          absence : 0
1462
 */
1463
u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot)
1464
{
1465
        unsigned int sta;
1466
 
1467
        sta = get_slot_status(slot);
1468
 
1469
        return (sta == 0) ? 0 : 1;
1470
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.