From owner-p4-projects@FreeBSD.ORG Fri Aug 20 17:12:44 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0F0A516A4D0; Fri, 20 Aug 2004 17:12:44 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A7E9F16A4CF for ; Fri, 20 Aug 2004 17:12:43 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 83F2743D5C for ; Fri, 20 Aug 2004 17:12:43 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i7KHChpv031124 for ; Fri, 20 Aug 2004 17:12:43 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i7KHChES031121 for perforce@freebsd.org; Fri, 20 Aug 2004 17:12:43 GMT (envelope-from jhb@freebsd.org) Date: Fri, 20 Aug 2004 17:12:43 GMT Message-Id: <200408201712.i7KHChES031121@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Subject: PERFORCE change 60152 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Aug 2004 17:12:44 -0000 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 -__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 @@ -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 void