Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/*
 *  acpi_pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 30 $)
 *
 *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
 *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or (at
 *  your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/spinlock.h>
#include <linux/pm.h>
#include <linux/pci.h>
#include <linux/acpi.h>
#include "acpi_bus.h"
#include "acpi_drivers.h"


#define _COMPONENT		ACPI_PCI_ROOT_COMPONENT
ACPI_MODULE_NAME		("pci_root")

MODULE_AUTHOR("Paul Diefenbaugh");
MODULE_DESCRIPTION(ACPI_PCI_ROOT_DRIVER_NAME);

extern struct pci_ops *pci_root_ops;

#define PREFIX			"ACPI: "

static int acpi_pci_root_add (struct acpi_device *device);
static int acpi_pci_root_remove (struct acpi_device *device, int type);
static int acpi_pci_root_bind (struct acpi_device *device);

static struct acpi_driver acpi_pci_root_driver = {
        name:                   ACPI_PCI_ROOT_DRIVER_NAME,
        class:                  ACPI_PCI_ROOT_CLASS,
        ids:                    ACPI_PCI_ROOT_HID,
        ops:                    {
                                        add:    acpi_pci_root_add,
                                        remove: acpi_pci_root_remove,
					bind:	acpi_pci_root_bind,
                                },
};

struct acpi_pci_data {
	acpi_pci_id		id;
	struct pci_dev		*dev;
};

struct acpi_pci_root {
	acpi_handle		handle;
	struct acpi_pci_data	data;
};

struct acpi_prt_list		acpi_prts;


/* --------------------------------------------------------------------------
                        PCI Routing Table (PRT) Support
   -------------------------------------------------------------------------- */

static int
acpi_prt_find_entry (
	acpi_pci_id		*id,
	u8			pin,
	struct acpi_prt_entry	**entry)
{
	struct list_head	*node = NULL;

	ACPI_FUNCTION_TRACE("acpi_prt_find_entry");

	if (!id || !entry)
		return_VALUE(-ENODEV);

	/* TBD: Locking */
	list_for_each(node, &acpi_prts.entries) {
		(*entry) = list_entry(node, struct acpi_prt_entry, node);
		/* TBD: Include check for segment when supported by pci_dev */
		if ((id->bus == (*entry)->id.bus) 
			&& (id->device == (*entry)->id.dev)
			&& (pin == (*entry)->id.pin)) {
			return_VALUE(0);
		}
	}

	(*entry) = NULL;

	return_VALUE(-ENODEV);
}


int
acpi_prt_get_irq (
	struct pci_dev		*dev,
	u8			pin,
	int			*irq)
{
	int			result = 0;
	struct acpi_prt_entry	*entry = NULL;
	acpi_pci_id		id = {0, 0, 0, 0};

	ACPI_FUNCTION_TRACE("acpi_prt_get_irq");

	if (!dev || !irq)
		return_VALUE(-ENODEV);

	if (!dev->bus) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Device has invalid 'bus' field\n"));
		return_VALUE(-EFAULT);
	}

	id.segment = 0;
	id.bus = dev->bus->number;
	id.device = PCI_SLOT(dev->devfn);
	id.function = PCI_FUNC(dev->devfn);

	ACPI_DEBUG_PRINT((ACPI_DB_INFO, 
		"Resolving IRQ for %02x:%02x:%02x.%02x[%c]\n",
		id.segment, id.bus, id.device, id.function, ('A'+pin)));

	result = acpi_prt_find_entry(&id, pin, &entry);
	if (0 != result)
		return_VALUE(result);

	/* Type 1: Dynamic (e.g. PCI Link Device) */
	if (entry->source.handle)
		result = acpi_pci_link_get_irq(entry, irq);

	/* Type 2: Static (e.g. I/O [S]APIC Direct) */
	else {
		if (entry->source.index)
			*irq = entry->source.index;
		else
			result = -ENODEV;
	}
	
	if (0 == result)
		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", *irq));
	else
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to reslove IRQ\n"));

	return_VALUE(0);
}


int
acpi_prt_set_irq (
	struct pci_dev		*dev,
	u8			pin,
	int			irq)
{
	int			result = 0;
	struct acpi_prt_entry	*entry = NULL;
	acpi_pci_id		id = {0, 0, 0, 0};

	ACPI_FUNCTION_TRACE("acpi_pci_set_irq");

	if (!dev || !irq)
		return_VALUE(-EINVAL);

	if (!dev->bus) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Device has invalid 'bus' field\n"));
		return_VALUE(-EFAULT);
	}

	id.segment = 0;
	id.bus = dev->bus->number;
	id.device = PCI_SLOT(dev->devfn);
	id.function = PCI_FUNC(dev->devfn);

	ACPI_DEBUG_PRINT((ACPI_DB_INFO, 
		"Setting %02x:%02x:%02x.%02x[%c] to IRQ%d\n",
		id.segment, id.bus, id.device, id.function, ('A'+pin), irq));

	result = acpi_prt_find_entry(&id, pin, &entry);
	if (0 != result)
		return_VALUE(result);

	/* Type 1: Dynamic (e.g. PCI Link Device) */
	if (entry->source.handle)
		result = acpi_pci_link_set_irq(entry, irq);
	/* Type 2: Static (e.g. I/O [S]APIC Direct) */
	else
		result = -EFAULT;
	
	if (0 == result)
		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "IRQ set\n"));
	else
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to set IRQ\n"));

	return_VALUE(result);
}


static int
acpi_prt_add_entry (
	acpi_handle		handle,
	u8			seg,
	u8			bus,
	acpi_pci_routing_table	*prt)
{
	struct acpi_prt_entry	*entry = NULL;

	ACPI_FUNCTION_TRACE("acpi_prt_add_entry");

	if (!prt)
		return_VALUE(-EINVAL);

	entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
	if (!entry)
		return_VALUE(-ENOMEM);
	memset(entry, 0, sizeof(struct acpi_prt_entry));

	entry->id.seg = seg;
	entry->id.bus = bus;
	entry->id.dev = prt->address >> 16;
	entry->id.pin = prt->pin;

	/*
	 * Type 1: Dynamic
	 * ---------------
	 * The 'source' field specifies the PCI interrupt link device used to
	 * configure the IRQ assigned to this slot|dev|pin.  The 'source_index'
	 * indicates which resource descriptor in the resource template (of
	 * the link device) this interrupt is allocated from.
	 */
	if (prt->source)
		acpi_get_handle(handle, prt->source, &entry->source.handle);
	/*
	 * Type 2: Static
	 * --------------
	 * The 'source' field is NULL, and the 'source_index' field specifies
	 * the IRQ value, which is hardwired to specific interrupt inputs on
	 * the interrupt controller.
	 */
	else
		entry->source.handle = NULL;

	entry->source.index = prt->source_index;

	/* 
	 * NOTE: Don't query the Link Device for IRQ information at this time
	 *       because Link Device enumeration may not have occurred yet
	 *       (e.g. exists somewhere 'below' this _PRT entry in the ACPI
	 *       namespace).
	 */

	ACPI_DEBUG_PRINT_RAW((ACPI_DB_OK, "      %02X:%02X:%02X[%c] -> %s[%d]\n", 
		entry->id.seg, entry->id.bus, entry->id.dev, 
		('A' + entry->id.pin), prt->source, entry->source.index));

	/* TBD: Acquire/release lock */
	list_add_tail(&entry->node, &acpi_prts.entries);

	acpi_prts.count++;

	return_VALUE(0);
}


static int
acpi_prt_parse (
	acpi_handle		handle,
	u8			seg,
	u8			bus)
{
	acpi_status		status = AE_OK;
	char			pathname[PATHNAME_MAX] = {0};
	acpi_buffer		buffer = {0, NULL};
	acpi_pci_routing_table	*prt = NULL;

	ACPI_FUNCTION_TRACE("acpi_prt_parse");

	buffer.length = sizeof(pathname);
	buffer.pointer = pathname;
	acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);

	printk(KERN_INFO PREFIX "%s [%s._PRT]\n", ACPI_PCI_PRT_DEVICE_NAME, 
		pathname);

	/* 
	 * Evaluate this _PRT and add all entries to our global list.
	 */

	buffer.length = 0;
	buffer.pointer = NULL;
	status = acpi_get_irq_routing_table(handle, &buffer);
	if (status != AE_BUFFER_OVERFLOW) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Error evaluating _PRT [%s]\n",
			acpi_format_exception(status)));
		return_VALUE(-ENODEV);
	}

	prt = kmalloc(buffer.length, GFP_KERNEL);
	if (!prt)
		return_VALUE(-ENOMEM);
	memset(prt, 0, buffer.length);
	buffer.pointer = prt;

	status = acpi_get_irq_routing_table(handle, &buffer);
	if (ACPI_FAILURE(status)) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Error evaluating _PRT [%s]\n",
			acpi_format_exception(status)));
		kfree(buffer.pointer);
		return_VALUE(-ENODEV);
	}

	while (prt && (prt->length > 0)) {
		acpi_prt_add_entry(handle, seg, bus, prt);
		prt = (acpi_pci_routing_table*)((unsigned long)prt + prt->length);
	}

	return_VALUE(0);
}


/* --------------------------------------------------------------------------
                             PCI Device Binding
   -------------------------------------------------------------------------- */

static void
acpi_pci_data_handler (
	acpi_handle		handle,
	u32			function,
	void			*context)
{
	ACPI_FUNCTION_TRACE("acpi_pci_data_handler");

	/* TBD: Anything we need to do here? */

	return_VOID;
}


/**
 * acpi_os_get_pci_id
 * ------------------
 * This function gets used by the ACPI Interpreter (a.k.a. Core Subsystem)
 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
 */
acpi_status
acpi_os_get_pci_id (
	acpi_handle		handle,
	acpi_pci_id		*id)
{
	int			result = 0;
	acpi_status		status = AE_OK;
	struct acpi_device	*device = NULL;
	struct acpi_pci_data	*data = NULL;

	ACPI_FUNCTION_TRACE("acpi_os_get_pci_id");

	if (!id)
		return_ACPI_STATUS(AE_BAD_PARAMETER);

	result = acpi_bus_get_device(handle, &device);
	if (0 != result) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Invalid ACPI Bus context for device %s\n",
			acpi_device_bid(device)));
		return_ACPI_STATUS(AE_NOT_EXIST);
	}

	status = acpi_get_data(handle, acpi_pci_data_handler, (void**) &data);
	if (ACPI_FAILURE(status) || !data || !data->dev) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Invalid ACPI-PCI context for device %s\n",
			acpi_device_bid(device)));
		return_ACPI_STATUS(status);
	}
	
	id->segment = data->id.segment;
	id->bus = data->id.bus;
	id->device = data->id.device;
	id->function = data->id.function;

	ACPI_DEBUG_PRINT((ACPI_DB_INFO, 
		"Device %s has PCI address %02x:%02x:%02x.%02x\n", 
		acpi_device_bid(device), id->segment, id->bus, 
		id->device, id->function));

	return_ACPI_STATUS(AE_OK);
}

	
static int
acpi_pci_root_bind (
	struct acpi_device	*device)
{
	int			result = 0;
	acpi_status		status = AE_OK;
	struct acpi_pci_data	*data = NULL;
	struct acpi_pci_data	*parent_data = NULL;
	acpi_handle		handle = NULL;

	ACPI_FUNCTION_TRACE("acpi_pci_root_bind");

	if (!device || !device->parent)
		return_VALUE(-EINVAL);

	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Attempting to bind PCI device %s.%s\n", 
		acpi_device_bid(device->parent), acpi_device_bid(device)));

	data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
	if (!data)
		return_VALUE(-ENOMEM);
	memset(data, 0, sizeof(struct acpi_pci_data));

	/* 
	 * Segment & Bus
	 * -------------
	 * These are obtained via the parent device's ACPI-PCI context..
	 * Note that PCI root bridge devices don't have a 'dev->subordinate'.
	 */
	status = acpi_get_data(device->parent->handle, acpi_pci_data_handler, 
		(void**) &parent_data);
	if (ACPI_FAILURE(status) || !parent_data || !parent_data->dev) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Invalid ACPI-PCI context for parent device %s\n",
			acpi_device_bid(device->parent)));
		result = -ENODEV;
		goto end;
	}

	data->id.segment = parent_data->id.segment;

	if (parent_data->dev->subordinate)	       /* e.g. PCI-PCI bridge */
		data->id.bus = parent_data->dev->subordinate->number;
	else if (parent_data->dev->bus)			   /* PCI root bridge */
		data->id.bus = parent_data->dev->bus->number;
	else {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Parent device %s is not a PCI bridge\n",
			acpi_device_bid(device->parent)));
		result = -ENODEV;
		goto end;
	}

	/*
	 * Device & Function
	 * -----------------
	 * These are simply obtained from the device's _ADR method.  Note
	 * that a value of zero is valid.
	 */
	data->id.device = device->pnp.bus_address >> 16;
	data->id.function = device->pnp.bus_address & 0xFFFF;

	ACPI_DEBUG_PRINT((ACPI_DB_INFO, 
		"Binding device %s.%s to %02x:%02x:%02x.%02x\n", 
		acpi_device_bid(device->parent), acpi_device_bid(device), 
		data->id.segment, data->id.bus, data->id.device, 
		data->id.function));

	/* 
	 * Locate PCI Device
	 * -----------------
	 * Locate matching device in PCI namespace.  If it doesn't exist
	 * this typically means that the device isn't currently inserted
	 * (e.g. docking station, port replicator, etc.).
	 */
	data->dev = pci_find_slot(data->id.bus, 
		PCI_DEVFN(data->id.device, data->id.function));
	if (!data->dev) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Device %02x:%02x:%02x.%02x not present in PCI namespace\n",
			data->id.segment, data->id.bus, 
			data->id.device, data->id.function));
		result = -ENODEV;
		goto end;
	}
	if (!data->dev->bus) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Device %02x:%02x:%02x.%02x has invalid 'bus' field\n",
			data->id.segment, data->id.bus, 
			data->id.device, data->id.function));
		result = -ENODEV;
		goto end;
	}

	/*
	 * Attach ACPI-PCI Context
	 * -----------------------
	 * Thus binding the ACPI and PCI devices.
	 */
	status = acpi_attach_data(device->handle, acpi_pci_data_handler, data);
	if (ACPI_FAILURE(status)) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
			"Unable to attach ACPI-PCI context to device %s\n",
			acpi_device_bid(device)));
		result = -ENODEV;
		goto end;
	}

	/*
	 * PCI Bridge?
	 * -----------
	 * If so, install the 'bind' function to facilitate callbacks for
	 * all of its children.
	 */
	if (data->dev->subordinate)
		device->ops.bind = acpi_pci_root_bind;

	/*
	 * PCI Routing Table
	 * -----------------
	 * Evaluate and parse _PRT, if exists.  This code is independent of 
	 * PCI bridges (above) to allow parsing of _PRT objects within the
	 * scope of non-bridge devices.  Note that _PRTs within the scope of
	 * a PCI bridge assume the bridge's subordinate bus number.
	 *
	 * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
	 */
	status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
	if (ACPI_SUCCESS(status)) {
		if (data->dev->subordinate)		    /* PCI-PCI bridge */
			acpi_prt_parse(device->handle, data->id.segment, 
				data->dev->subordinate->number);
		else				     /* non-bridge PCI device */
			acpi_prt_parse(device->handle, data->id.segment,
				data->id.bus);
	}

end:
	if (0 != result)
		kfree(data);

	return_VALUE(result);
}


/* --------------------------------------------------------------------------
                                Driver Interface
   -------------------------------------------------------------------------- */

static int
acpi_pci_root_add (
	struct acpi_device	*device)
{
	int			result = 0;
	struct acpi_pci_root	*root = NULL;
	acpi_status		status = AE_OK;
	unsigned long		value = 0;

	ACPI_FUNCTION_TRACE("acpi_pci_root_add");

	if (!device)
		return_VALUE(-EINVAL);

	root = kmalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
	if (!root)
		return_VALUE(-ENOMEM);
	memset(root, 0, sizeof(struct acpi_pci_root));

	root->handle = device->handle;
	sprintf(acpi_device_name(device), "%s", ACPI_PCI_ROOT_DEVICE_NAME);
	sprintf(acpi_device_class(device), "%s", ACPI_PCI_ROOT_CLASS);
	acpi_driver_data(device) = root;

	/*
	 * TBD: Doesn't the bus driver automatically set this?
	 */
	device->ops.bind = acpi_pci_root_bind;

	/* 
	 * Segment
	 * -------
	 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
	 */
	status = acpi_evaluate_integer(root->handle, METHOD_NAME__SEG, NULL, 
		&value);
	switch (status) {
	case AE_OK:
		root->data.id.segment = (u16) value;
		break;
	case AE_NOT_FOUND:
		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Assuming segment 0 (no _SEG)\n"));
		root->data.id.segment = 0;
		break;
	default:
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _SEG\n"));
		result = -ENODEV;
		goto end;
	}

	/* 
	 * Bus
	 * ---
	 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
	 */
	status = acpi_evaluate_integer(root->handle, METHOD_NAME__BBN, NULL, 
		&value);
	switch (status) {
	case AE_OK:
		root->data.id.bus = (u16) value;
		break;
	case AE_NOT_FOUND:
		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Assuming bus 0 (no _BBN)\n"));
		root->data.id.bus = 0;
		break;
	default:
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _BBN\n"));
		result = -ENODEV;
		goto end;
	}

	/*
	 * Device & Function
	 * -----------------
	 * Obtained from _ADR (which has already been evaluated for us).
	 */
	root->data.id.device = device->pnp.bus_address >> 16;
	root->data.id.function = device->pnp.bus_address & 0xFFFF;

	/*
	 * TBD: Evaluate _CRS to get root bridge resources
	 * TBD: Need PCI interface for enumeration/configuration of roots.
	 */

	printk(KERN_INFO PREFIX "%s [%s] (%02x:%02x:%02x.%02x)\n", 
		acpi_device_name(device), acpi_device_bid(device),
		root->data.id.segment, root->data.id.bus, 
		root->data.id.device, root->data.id.function);

	/*
	 * Scan the Root Bridge
	 * --------------------
	 * Must do this prior to any attempt to bind the root device, as the
	 * PCI namespace does not get created until this call is made (and 
	 * thus the root bridge's pci_dev does not exist).
	 */
	pci_scan_bus(root->data.id.bus, pci_root_ops, NULL);

	/* 
	 * Locate PCI Device
	 * -----------------
	 * Locate the matching PCI root bridge device in the PCI namespace.
	 */
	root->data.dev = pci_find_slot(root->data.id.bus, 
		PCI_DEVFN(root->data.id.device, root->data.id.function));
	if (!root->data.dev) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
			"Device %02x:%02x:%02x.%02x not present\n", 
			root->data.id.segment, root->data.id.bus, 
			root->data.id.device, root->data.id.function));
		result = -ENODEV;
		goto end;
	}

	/*
	 * Attach ACPI-PCI Context
	 * -----------------------
	 * Thus binding the ACPI and PCI devices.
	 */
	status = acpi_attach_data(root->handle, acpi_pci_data_handler, 
		&root->data);
	if (ACPI_FAILURE(status)) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
			"Unable to attach ACPI-PCI context to device %s\n",
			acpi_device_bid(device)));
		result = -ENODEV;
		goto end;
	}

	/*
	 * PCI Routing Table
	 * -----------------
	 * Evaluate and parse _PRT, if exists.  Note that root bridges
	 * must have a _PRT (optional for subordinate bridges).
	 */
	result = acpi_prt_parse(device->handle, root->data.id.segment, 
		root->data.id.bus);

end:
	if (0 != result)
		kfree(root);

	return_VALUE(result);
}


static int
acpi_pci_root_remove (
	struct acpi_device	*device,
	int			type)
{
	struct acpi_pci_root	*root = NULL;

	ACPI_FUNCTION_TRACE("acpi_pci_root_remove");

	if (!device || !acpi_driver_data(device))
		return_VALUE(-EINVAL);

	root = (struct acpi_pci_root *) acpi_driver_data(device);

	kfree(root);

	return_VALUE(0);
}


int __init
acpi_pci_root_init (void)
{
	ACPI_FUNCTION_TRACE("acpi_pci_root_init");

	acpi_prts.count = 0;
	INIT_LIST_HEAD(&acpi_prts.entries);

	if (0 > acpi_bus_register_driver(&acpi_pci_root_driver))
		return_VALUE(-ENODEV);

	return_VALUE(0);
}


void __exit
acpi_pci_root_exit (void)
{
	ACPI_FUNCTION_TRACE("acpi_pci_root_exit");

	acpi_bus_unregister_driver(&acpi_pci_root_driver);

	return_VOID;
}