Date: Fri, 20 Aug 2004 17:12:43 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 60152 for review Message-ID: <200408201712.i7KHChES031121@repoman.freebsd.org>
index | next in thread | raw e-mail
http://perforce.freebsd.org/chv.cgi?CH=60152 Change 60152 by jhb@jhb_slimer on 2004/08/20 17:11:42 IFC @60150. Affected files ... .. //depot/projects/smpng/sys/dev/acpica/acpi_resource.c#20 integrate Differences ... ==== //depot/projects/smpng/sys/dev/acpica/acpi_resource.c#20 (text+ko) ==== @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/sys/dev/acpica/acpi_resource.c,v 1.28 2004/08/13 06:22:13 njl Exp $"); +__FBSDID("$FreeBSD: src/sys/dev/acpica/acpi_resource.c,v 1.30 2004/08/20 17:04:49 njl Exp $"); #include "opt_acpi.h" #include <sys/param.h> @@ -504,6 +504,51 @@ void *ar_parent; }; +/* + * Add a resource to the device's resource list. We define our own function + * for this since bus_set_resource() doesn't handle duplicates of any kind. + * + * XXX This should be merged into resource_list_add() eventually. + */ +static int +acpi_reslist_add(device_t dev, int type, int rid, u_long start, u_long count) +{ + struct resource_list_entry *rle; + struct resource_list *rl; + u_long end; + + end = start + count - 1; + rl = BUS_GET_RESOURCE_LIST(device_get_parent(dev), dev); + + /* + * Loop through all current resources to see if the new one overlaps + * any existing ones. If so, the old one always takes precedence and + * the new one is adjusted (or rejected). We check for three cases: + * + * 1. Tail of new resource overlaps head of old resource: truncate the + * new resource so it is contiguous with the start of the old. + * 2. New resource wholly contained within the old resource: error. + * 3. Head of new resource overlaps tail of old resource: truncate the + * new resource so it is contiguous, following the old. + */ + SLIST_FOREACH(rle, rl, link) { + if (rle->type == type) { + if (start < rle->start && end >= rle->start) { + count = rle->start - start; + break; + } else if (start >= rle->start && start <= rle->end) { + if (end > rle->end) { + start = rle->end + 1; + count = end - start + 1; + break; + } else + return (EEXIST); + } + } + } + return (bus_set_resource(dev, type, rid, start, count)); +} + static void acpi_res_set_init(device_t dev, void *arg, void **context) { @@ -534,7 +579,7 @@ if (cp == NULL) return; - bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length); + acpi_reslist_add(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length); } static void @@ -557,7 +602,7 @@ if (cp == NULL) return; - bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length); + acpi_reslist_add(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length); } static void @@ -584,7 +629,7 @@ if (count != 1) return; - bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1); + acpi_reslist_add(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1); } static void @@ -599,7 +644,7 @@ if (count != 1) return; - bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1); + acpi_reslist_add(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1); } static voidhelp
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200408201712.i7KHChES031121>
