2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: head/sys/dev/acpica/acpi_resource.c 263975 2014-03-31 19:37:39Z imp $
31 #include <sys/param.h>
32 #include <sys/kernel.h>
34 #include <sys/limits.h>
35 #include <sys/malloc.h>
36 #include <sys/module.h>
37 #include <sys/resource.h>
38 #include <sys/machintr.h>
43 #include <dev/acpica/acpivar.h>
45 /* Hooks for the ACPICA debugging infrastructure */
46 #define _COMPONENT ACPI_BUS
47 ACPI_MODULE_NAME("RESOURCE")
49 struct lookup_irq_request
{
50 ACPI_RESOURCE
*acpi_res
;
58 acpi_lookup_irq_handler(ACPI_RESOURCE
*res
, void *context
)
60 struct lookup_irq_request
*req
;
66 case ACPI_RESOURCE_TYPE_IRQ
:
67 irqnum
= res
->Data
.Irq
.InterruptCount
;
68 irq
= res
->Data
.Irq
.Interrupts
[0];
69 len
= ACPI_RS_SIZE(ACPI_RESOURCE_IRQ
);
71 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
72 irqnum
= res
->Data
.ExtendedIrq
.InterruptCount
;
73 irq
= res
->Data
.ExtendedIrq
.Interrupts
[0];
74 len
= ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ
);
81 req
= (struct lookup_irq_request
*)context
;
82 if (req
->counter
!= req
->rid
) {
87 KASSERT(irq
== rman_get_start(req
->res
),
88 ("IRQ resources do not match"));
89 bcopy(res
, req
->acpi_res
, len
);
90 return (AE_CTRL_TERMINATE
);
94 acpi_lookup_irq_resource(device_t dev
, int rid
, struct resource
*res
,
95 ACPI_RESOURCE
*acpi_res
)
97 struct lookup_irq_request req
;
100 req
.acpi_res
= acpi_res
;
105 status
= AcpiWalkResources(acpi_get_handle(dev
), "_CRS",
106 acpi_lookup_irq_handler
, &req
);
107 if (ACPI_SUCCESS(status
) && req
.found
== 0)
108 status
= AE_NOT_FOUND
;
113 acpi_config_intr(device_t dev
, ACPI_RESOURCE
*res
)
117 enum intr_trigger trigger
;
118 enum intr_polarity polarity
;
121 case ACPI_RESOURCE_TYPE_IRQ
:
122 KASSERT(res
->Data
.Irq
.InterruptCount
== 1,
123 ("%s: multiple interrupts", __func__
));
124 irq
= res
->Data
.Irq
.Interrupts
[0];
125 trig
= res
->Data
.Irq
.Triggering
;
126 pol
= res
->Data
.Irq
.Polarity
;
128 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
129 KASSERT(res
->Data
.ExtendedIrq
.InterruptCount
== 1,
130 ("%s: multiple interrupts", __func__
));
131 irq
= res
->Data
.ExtendedIrq
.Interrupts
[0];
132 trig
= res
->Data
.ExtendedIrq
.Triggering
;
133 pol
= res
->Data
.ExtendedIrq
.Polarity
;
136 panic("%s: bad resource type %u", __func__
, res
->Type
);
139 #if defined(__x86_64__)
141 * XXX: Certain BIOSes have buggy AML that specify an IRQ that is
142 * edge-sensitive and active-lo. However, edge-sensitive IRQs
143 * should be active-hi. Force IRQs with an ISA IRQ value to be
146 if (irq
< 16 && trig
== ACPI_EDGE_SENSITIVE
&& pol
== ACPI_ACTIVE_LOW
)
147 pol
= ACPI_ACTIVE_HIGH
;
150 if (trig
== ACPI_EDGE_SENSITIVE
)
151 trigger
= INTR_TRIGGER_EDGE
;
153 trigger
= INTR_TRIGGER_LEVEL
;
155 if (pol
== ACPI_ACTIVE_HIGH
)
156 polarity
= INTR_POLARITY_HIGH
;
158 polarity
= INTR_POLARITY_LOW
;
160 if (machintr_legacy_intr_find(irq
, trigger
, polarity
) < 0)
161 kprintf("%s: Skip irq %d config\n", __func__
, irq
);
163 BUS_CONFIG_INTR(dev
, dev
, irq
, trigger
, polarity
);
166 struct acpi_resource_context
{
167 struct acpi_parse_resource_set
*set
;
172 #ifdef ACPI_DEBUG_OUTPUT
174 acpi_address_range_name(UINT8 ResourceType
)
178 switch (ResourceType
) {
179 case ACPI_MEMORY_RANGE
:
183 case ACPI_BUS_NUMBER_RANGE
:
184 return ("Bus Number");
186 ksnprintf(buf
, sizeof(buf
), "type %u", ResourceType
);
193 acpi_parse_resource(ACPI_RESOURCE
*res
, void *context
)
195 struct acpi_parse_resource_set
*set
;
196 struct acpi_resource_context
*arc
;
197 UINT64 min
, max
, length
, gran
;
208 case ACPI_RESOURCE_TYPE_END_TAG
:
209 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "EndTag\n"));
211 case ACPI_RESOURCE_TYPE_FIXED_IO
:
212 if (res
->Data
.FixedIo
.AddressLength
<= 0)
214 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "FixedIo 0x%x/%d\n",
215 res
->Data
.FixedIo
.Address
, res
->Data
.FixedIo
.AddressLength
));
216 set
->set_ioport(dev
, arc
->context
, res
->Data
.FixedIo
.Address
,
217 res
->Data
.FixedIo
.AddressLength
);
219 case ACPI_RESOURCE_TYPE_IO
:
220 if (res
->Data
.Io
.AddressLength
<= 0)
222 if (res
->Data
.Io
.Minimum
== res
->Data
.Io
.Maximum
) {
223 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "Io 0x%x/%d\n",
224 res
->Data
.Io
.Minimum
, res
->Data
.Io
.AddressLength
));
225 set
->set_ioport(dev
, arc
->context
, res
->Data
.Io
.Minimum
,
226 res
->Data
.Io
.AddressLength
);
228 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "Io 0x%x-0x%x/%d\n",
229 res
->Data
.Io
.Minimum
, res
->Data
.Io
.Maximum
,
230 res
->Data
.Io
.AddressLength
));
231 set
->set_iorange(dev
, arc
->context
, res
->Data
.Io
.Minimum
,
232 res
->Data
.Io
.Maximum
, res
->Data
.Io
.AddressLength
,
233 res
->Data
.Io
.Alignment
);
236 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
237 if (res
->Data
.FixedMemory32
.AddressLength
<= 0)
239 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "FixedMemory32 0x%x/%d\n",
240 res
->Data
.FixedMemory32
.Address
,
241 res
->Data
.FixedMemory32
.AddressLength
));
242 set
->set_memory(dev
, arc
->context
, res
->Data
.FixedMemory32
.Address
,
243 res
->Data
.FixedMemory32
.AddressLength
);
245 case ACPI_RESOURCE_TYPE_MEMORY32
:
246 if (res
->Data
.Memory32
.AddressLength
<= 0)
248 if (res
->Data
.Memory32
.Minimum
== res
->Data
.Memory32
.Maximum
) {
249 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "Memory32 0x%x/%d\n",
250 res
->Data
.Memory32
.Minimum
, res
->Data
.Memory32
.AddressLength
));
251 set
->set_memory(dev
, arc
->context
, res
->Data
.Memory32
.Minimum
,
252 res
->Data
.Memory32
.AddressLength
);
254 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "Memory32 0x%x-0x%x/%d\n",
255 res
->Data
.Memory32
.Minimum
, res
->Data
.Memory32
.Maximum
,
256 res
->Data
.Memory32
.AddressLength
));
257 set
->set_memoryrange(dev
, arc
->context
, res
->Data
.Memory32
.Minimum
,
258 res
->Data
.Memory32
.Maximum
, res
->Data
.Memory32
.AddressLength
,
259 res
->Data
.Memory32
.Alignment
);
262 case ACPI_RESOURCE_TYPE_MEMORY24
:
263 if (res
->Data
.Memory24
.AddressLength
<= 0)
265 if (res
->Data
.Memory24
.Minimum
== res
->Data
.Memory24
.Maximum
) {
266 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "Memory24 0x%x/%d\n",
267 res
->Data
.Memory24
.Minimum
, res
->Data
.Memory24
.AddressLength
));
268 set
->set_memory(dev
, arc
->context
, res
->Data
.Memory24
.Minimum
,
269 res
->Data
.Memory24
.AddressLength
);
271 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "Memory24 0x%x-0x%x/%d\n",
272 res
->Data
.Memory24
.Minimum
, res
->Data
.Memory24
.Maximum
,
273 res
->Data
.Memory24
.AddressLength
));
274 set
->set_memoryrange(dev
, arc
->context
, res
->Data
.Memory24
.Minimum
,
275 res
->Data
.Memory24
.Maximum
, res
->Data
.Memory24
.AddressLength
,
276 res
->Data
.Memory24
.Alignment
);
279 case ACPI_RESOURCE_TYPE_IRQ
:
282 * "This structure is repeated for each separate interrupt
285 set
->set_irq(dev
, arc
->context
, res
->Data
.Irq
.Interrupts
,
286 res
->Data
.Irq
.InterruptCount
, res
->Data
.Irq
.Triggering
,
287 res
->Data
.Irq
.Polarity
);
289 case ACPI_RESOURCE_TYPE_DMA
:
292 * "This structure is repeated for each separate DMA channel
295 set
->set_drq(dev
, arc
->context
, res
->Data
.Dma
.Channels
,
296 res
->Data
.Dma
.ChannelCount
);
298 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
299 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "start dependent functions\n"));
300 set
->set_start_dependent(dev
, arc
->context
,
301 res
->Data
.StartDpf
.CompatibilityPriority
);
303 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
304 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "end dependent functions\n"));
305 set
->set_end_dependent(dev
, arc
->context
);
307 case ACPI_RESOURCE_TYPE_ADDRESS16
:
308 case ACPI_RESOURCE_TYPE_ADDRESS32
:
309 case ACPI_RESOURCE_TYPE_ADDRESS64
:
310 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
312 case ACPI_RESOURCE_TYPE_ADDRESS16
:
313 gran
= res
->Data
.Address16
.Address
.Granularity
;
314 min
= res
->Data
.Address16
.Address
.Minimum
;
315 max
= res
->Data
.Address16
.Address
.Maximum
;
316 length
= res
->Data
.Address16
.Address
.AddressLength
;
321 case ACPI_RESOURCE_TYPE_ADDRESS32
:
322 gran
= res
->Data
.Address32
.Address
.Granularity
;
323 min
= res
->Data
.Address32
.Address
.Minimum
;
324 max
= res
->Data
.Address32
.Address
.Maximum
;
325 length
= res
->Data
.Address32
.Address
.AddressLength
;
330 case ACPI_RESOURCE_TYPE_ADDRESS64
:
331 gran
= res
->Data
.Address64
.Address
.Granularity
;
332 min
= res
->Data
.Address64
.Address
.Minimum
;
333 max
= res
->Data
.Address64
.Address
.Maximum
;
334 length
= res
->Data
.Address64
.Address
.AddressLength
;
340 KASSERT(res
->Type
== ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
,
341 ("should never happen"));
342 gran
= res
->Data
.ExtAddress64
.Address
.Granularity
;
343 min
= res
->Data
.ExtAddress64
.Address
.Minimum
;
344 max
= res
->Data
.ExtAddress64
.Address
.Maximum
;
345 length
= res
->Data
.ExtAddress64
.Address
.AddressLength
;
347 name
= "ExtAddress64";
353 if (res
->Data
.Address
.ProducerConsumer
!= ACPI_CONSUMER
) {
354 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
,
355 "ignored %s %s producer\n", name
,
356 acpi_address_range_name(res
->Data
.Address
.ResourceType
)));
359 if (res
->Data
.Address
.ResourceType
!= ACPI_MEMORY_RANGE
&&
360 res
->Data
.Address
.ResourceType
!= ACPI_IO_RANGE
) {
361 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
,
362 "ignored %s for non-memory, non-I/O\n", name
));
365 if (res
->Data
.Address
.MinAddressFixed
== ACPI_ADDRESS_FIXED
&&
366 res
->Data
.Address
.MaxAddressFixed
== ACPI_ADDRESS_FIXED
) {
367 if (res
->Data
.Address
.ResourceType
== ACPI_MEMORY_RANGE
) {
368 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "%s/Memory 0x%jx/%ju\n",
369 name
, (uintmax_t)min
, (uintmax_t)length
));
370 set
->set_memory(dev
, arc
->context
, min
, length
);
372 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "%s/IO 0x%jx/%ju\n", name
,
373 (uintmax_t)min
, (uintmax_t)length
));
374 set
->set_ioport(dev
, arc
->context
, min
, length
);
377 if (res
->Data
.Address32
.ResourceType
== ACPI_MEMORY_RANGE
) {
378 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
,
379 "%s/Memory 0x%jx-0x%jx/%ju\n", name
, (uintmax_t)min
,
380 (uintmax_t)max
, (uintmax_t)length
));
381 set
->set_memoryrange(dev
, arc
->context
, min
, max
, length
, gran
);
383 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "%s/IO 0x%jx-0x%jx/%ju\n",
384 name
, (uintmax_t)min
, (uintmax_t)max
, (uintmax_t)length
));
385 set
->set_iorange(dev
, arc
->context
, min
, max
, length
, gran
);
389 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
390 if (res
->Data
.ExtendedIrq
.ProducerConsumer
!= ACPI_CONSUMER
) {
391 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
, "ignored ExtIRQ producer\n"));
394 set
->set_ext_irq(dev
, arc
->context
, res
->Data
.ExtendedIrq
.Interrupts
,
395 res
->Data
.ExtendedIrq
.InterruptCount
,
396 res
->Data
.ExtendedIrq
.Triggering
, res
->Data
.ExtendedIrq
.Polarity
);
398 case ACPI_RESOURCE_TYPE_VENDOR
:
399 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES
,
400 "unimplemented VendorSpecific resource\n"));
409 * Fetch a device's resources and associate them with the device.
411 * Note that it might be nice to also locate ACPI-specific resource items, such
414 * We really need to split the resource-fetching code out from the
415 * resource-parsing code, since we may want to use the parsing
416 * code for _PRS someday.
419 acpi_parse_resources(device_t dev
, ACPI_HANDLE handle
,
420 struct acpi_parse_resource_set
*set
, void *arg
)
422 struct acpi_resource_context arc
;
425 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__
);
427 set
->set_init(dev
, arg
, &arc
.context
);
430 status
= AcpiWalkResources(handle
, "_CRS", acpi_parse_resource
, &arc
);
431 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
432 kprintf("can't fetch resources for %s - %s\n",
433 acpi_name(handle
), AcpiFormatException(status
));
434 return_ACPI_STATUS (status
);
436 set
->set_done(dev
, arc
.context
);
437 return_ACPI_STATUS (AE_OK
);
441 * Resource-set vectors used to attach _CRS-derived resources
444 static void acpi_res_set_init(device_t dev
, void *arg
, void **context
);
445 static void acpi_res_set_done(device_t dev
, void *context
);
446 static void acpi_res_set_ioport(device_t dev
, void *context
,
447 uint64_t base
, uint64_t length
);
448 static void acpi_res_set_iorange(device_t dev
, void *context
,
449 uint64_t low
, uint64_t high
,
450 uint64_t length
, uint64_t align
);
451 static void acpi_res_set_memory(device_t dev
, void *context
,
452 uint64_t base
, uint64_t length
);
453 static void acpi_res_set_memoryrange(device_t dev
, void *context
,
454 uint64_t low
, uint64_t high
,
455 uint64_t length
, uint64_t align
);
456 static void acpi_res_set_irq(device_t dev
, void *context
, uint8_t *irq
,
457 int count
, int trig
, int pol
);
458 static void acpi_res_set_ext_irq(device_t dev
, void *context
,
459 uint32_t *irq
, int count
, int trig
, int pol
);
460 static void acpi_res_set_drq(device_t dev
, void *context
, uint8_t *drq
,
462 static void acpi_res_set_start_dependent(device_t dev
, void *context
,
464 static void acpi_res_set_end_dependent(device_t dev
, void *context
);
466 struct acpi_parse_resource_set acpi_res_parse_set
= {
470 acpi_res_set_iorange
,
472 acpi_res_set_memoryrange
,
474 acpi_res_set_ext_irq
,
476 acpi_res_set_start_dependent
,
477 acpi_res_set_end_dependent
480 struct acpi_res_context
{
489 acpi_res_set_init(device_t dev
, void *arg
, void **context
)
491 struct acpi_res_context
*cp
;
493 if ((cp
= AcpiOsAllocate(sizeof(*cp
))) != NULL
) {
494 bzero(cp
, sizeof(*cp
));
501 acpi_res_set_done(device_t dev
, void *context
)
503 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
511 acpi_res_set_ioport(device_t dev
, void *context
, uint64_t base
,
514 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
518 bus_set_resource(dev
, SYS_RES_IOPORT
, cp
->ar_nio
++, base
, length
, -1);
522 acpi_res_set_iorange(device_t dev
, void *context
, uint64_t low
,
523 uint64_t high
, uint64_t length
, uint64_t align
)
525 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
531 base
= roundup(low
, align
);
532 if (base
+ length
- 1 <= high
) {
533 acpi_res_set_ioport(dev
, context
, base
, length
);
536 device_printf(dev
, "I/O range [0x%jx,0x%jx,0x%jx,0x%jx] not supported\n",
537 (uintmax_t)low
, (uintmax_t)high
, (uintmax_t)length
, (uintmax_t)align
);
541 acpi_res_set_memory(device_t dev
, void *context
, uint64_t base
,
544 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
549 bus_set_resource(dev
, SYS_RES_MEMORY
, cp
->ar_nmem
++, base
, length
, -1);
553 acpi_res_set_memoryrange(device_t dev
, void *context
, uint64_t low
,
554 uint64_t high
, uint64_t length
, uint64_t align
)
556 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
560 device_printf(dev
, "memory range [0x%jx,0x%jx,0x%jx,0x%jx] "
562 (uintmax_t)low
, (uintmax_t)high
, (uintmax_t)length
, (uintmax_t)align
);
566 acpi_res_set_irq(device_t dev
, void *context
, uint8_t *irq
, int count
,
569 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
571 if (cp
== NULL
|| irq
== NULL
)
574 /* This implements no resource relocation. */
578 bus_set_resource(dev
, SYS_RES_IRQ
, cp
->ar_nirq
++, *irq
, 1,
579 machintr_legacy_intr_cpuid(*irq
));
583 acpi_res_set_ext_irq(device_t dev
, void *context
, uint32_t *irq
, int count
,
586 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
588 if (cp
== NULL
|| irq
== NULL
)
591 /* This implements no resource relocation. */
595 /* There is no such IRQ at all */
596 if (machintr_legacy_intr_find(*irq
,
597 INTR_TRIGGER_CONFORM
, INTR_POLARITY_CONFORM
) < 0)
600 bus_set_resource(dev
, SYS_RES_IRQ
, cp
->ar_nirq
++, *irq
, 1,
601 machintr_legacy_intr_cpuid(*irq
));
605 acpi_res_set_drq(device_t dev
, void *context
, uint8_t *drq
, int count
)
607 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
609 if (cp
== NULL
|| drq
== NULL
)
612 /* This implements no resource relocation. */
616 bus_set_resource(dev
, SYS_RES_DRQ
, cp
->ar_ndrq
++, *drq
, 1, -1);
620 acpi_res_set_start_dependent(device_t dev
, void *context
, int preference
)
622 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
626 device_printf(dev
, "dependent functions not supported\n");
630 acpi_res_set_end_dependent(device_t dev
, void *context
)
632 struct acpi_res_context
*cp
= (struct acpi_res_context
*)context
;
636 device_printf(dev
, "dependent functions not supported\n");
640 * Resource-owning placeholders for IO and memory pseudo-devices.
642 * This code allocates system resources that will be used by ACPI
643 * child devices. The acpi parent manages these resources through a
647 static int acpi_sysres_rid
= 100;
649 static int acpi_sysres_probe(device_t dev
);
650 static int acpi_sysres_attach(device_t dev
);
652 static device_method_t acpi_sysres_methods
[] = {
653 /* Device interface */
654 DEVMETHOD(device_probe
, acpi_sysres_probe
),
655 DEVMETHOD(device_attach
, acpi_sysres_attach
),
660 static driver_t acpi_sysres_driver
= {
666 static devclass_t acpi_sysres_devclass
;
667 DRIVER_MODULE(acpi_sysresource
, acpi
, acpi_sysres_driver
, acpi_sysres_devclass
,
669 MODULE_DEPEND(acpi_sysresource
, acpi
, 1, 1, 1);
672 acpi_sysres_probe(device_t dev
)
674 static char *sysres_ids
[] = { "PNP0C01", "PNP0C02", NULL
};
676 if (acpi_disabled("sysresource") ||
677 ACPI_ID_PROBE(device_get_parent(dev
), dev
, sysres_ids
) == NULL
)
680 device_set_desc(dev
, "System Resource");
682 return (BUS_PROBE_DEFAULT
);
686 acpi_sysres_attach(device_t dev
)
689 struct resource_list_entry
*bus_rle
, *dev_rle
;
690 struct resource_list
*bus_rl
, *dev_rl
;
692 u_long start
, end
, count
;
695 * Loop through all current resources to see if the new one overlaps
696 * any existing ones. If so, grow the old one up and/or down
697 * accordingly. Discard any that are wholly contained in the old. If
698 * the resource is unique, add it to the parent. It will later go into
701 bus
= device_get_parent(dev
);
702 dev_rl
= BUS_GET_RESOURCE_LIST(bus
, dev
);
703 bus_rl
= BUS_GET_RESOURCE_LIST(device_get_parent(bus
), bus
);
705 kprintf("busrl is not null!\n");
706 SLIST_FOREACH(dev_rle
, dev_rl
, link
) {
707 if (dev_rle
->type
!= SYS_RES_IOPORT
&& dev_rle
->type
!= SYS_RES_MEMORY
)
710 start
= dev_rle
->start
;
712 count
= dev_rle
->count
;
713 type
= dev_rle
->type
;
716 SLIST_FOREACH(bus_rle
, bus_rl
, link
) {
717 if (bus_rle
->type
!= type
)
720 /* New resource wholly contained in old, discard. */
721 if (start
>= bus_rle
->start
&& end
<= bus_rle
->end
)
724 /* New tail overlaps old head, grow existing resource downward. */
725 if (start
< bus_rle
->start
&& end
>= bus_rle
->start
) {
726 bus_rle
->count
+= bus_rle
->start
- start
;
727 bus_rle
->start
= start
;
731 /* New head overlaps old tail, grow existing resource upward. */
732 if (start
<= bus_rle
->end
&& end
> bus_rle
->end
) {
733 bus_rle
->count
+= end
- bus_rle
->end
;
738 /* If we adjusted the old resource, we're finished. */
745 /* If we didn't merge with anything, add this resource. */
747 bus_set_resource(bus
, type
, acpi_sysres_rid
++, start
, count
, -1);
750 /* After merging/moving resources to the parent, free the list. */
751 resource_list_free(dev_rl
);