From owner-p4-projects@FreeBSD.ORG Wed Sep 17 23:41:51 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 74CC01065679; Wed, 17 Sep 2008 23:41:51 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 39DDA1065670 for ; Wed, 17 Sep 2008 23:41:51 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 268458FC1E for ; Wed, 17 Sep 2008 23:41:51 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m8HNfpi9067717 for ; Wed, 17 Sep 2008 23:41:51 GMT (envelope-from peter-gmail@wemm.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m8HNfp7p067715 for perforce@freebsd.org; Wed, 17 Sep 2008 23:41:51 GMT (envelope-from peter-gmail@wemm.org) Date: Wed, 17 Sep 2008 23:41:51 GMT Message-Id: <200809172341.m8HNfp7p067715@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter-gmail@wemm.org using -f From: Peter Wemm To: Perforce Change Reviews Cc: Subject: PERFORCE change 149980 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Sep 2008 23:41:51 -0000 http://perforce.freebsd.org/chv.cgi?CH=149980 Change 149980 by peter@peter_daintree on 2008/09/17 23:41:35 WIP. attempt to match up acpi devices with their unit hints. Affected files ... .. //depot/projects/hammer/sys/dev/uart/uart_bus_acpi.c#4 edit Differences ... ==== //depot/projects/hammer/sys/dev/uart/uart_bus_acpi.c#4 (text+ko) ==== @@ -41,11 +41,12 @@ #include static int uart_acpi_probe(device_t dev); +static int uart_acpi_attach(device_t dev); static device_method_t uart_acpi_methods[] = { /* Device interface */ DEVMETHOD(device_probe, uart_acpi_probe), - DEVMETHOD(device_attach, uart_bus_attach), + DEVMETHOD(device_attach, uart_acpi_attach), DEVMETHOD(device_detach, uart_bus_detach), { 0, 0 } }; @@ -80,4 +81,49 @@ return (ENXIO); } +/* XXX find matching 'port' if it exists. */ +/* + * Don't cut and paste this to other drivers. It is a horrible kludge + * which will fail to work and also be unnecessary in future versions. + */ +static void +uart_acpi_kludge_unit(device_t dev) +{ + devclass_t dc; + int err; + int start; + int unit; + u_int port; + + port = isa_get_port(dev); + if (port == -1) + device_printf(dev, "cannot find start port"); + unit = 0; + start = 0; + while (resource_int_value("uart", unit, "port", &start) == 0 && + start > 0) { + if (start == port) + break; + else + unit++; + } + if (device_get_unit(dev) < unit) { + dc = device_get_devclass(dev); + while (devclass_get_device(dc, unit)) + unit++; + device_printf(dev, "moving to uart%d\n", unit); + err = device_set_unit(dev, unit); /* EVIL DO NOT COPY */ + if (err) + device_printf(dev, "error moving device %d\n", err); + } +} + +static int +uart_acpi_attach(device_t dev) +{ + + uart_acpi_kludge_unit(dev); + return (uart_bus_attach(dev)); +} + DRIVER_MODULE(uart, acpi, uart_acpi_driver, uart_devclass, 0, 0);