From owner-p4-projects@FreeBSD.ORG Sat Apr 15 21:24:15 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 49AC416A405; Sat, 15 Apr 2006 21:24:15 +0000 (UTC) X-Original-To: perforce@freebsd.org 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 EC05F16A403 for ; Sat, 15 Apr 2006 21:24:14 +0000 (UTC) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 95D4343D64 for ; Sat, 15 Apr 2006 21:24:14 +0000 (GMT) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k3FLOETh089296 for ; Sat, 15 Apr 2006 21:24:14 GMT (envelope-from marcel@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k3FLOE5H089293 for perforce@freebsd.org; Sat, 15 Apr 2006 21:24:14 GMT (envelope-from marcel@freebsd.org) Date: Sat, 15 Apr 2006 21:24:14 GMT Message-Id: <200604152124.k3FLOE5H089293@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to marcel@freebsd.org using -f From: Marcel Moolenaar To: Perforce Change Reviews Cc: Subject: PERFORCE change 95355 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: Sat, 15 Apr 2006 21:24:15 -0000 http://perforce.freebsd.org/chv.cgi?CH=95355 Change 95355 by marcel@marcel_nfs on 2006/04/15 21:23:24 o Create child devices o Probe and attach child devices Affected files ... .. //depot/projects/uart/dev/puc/puc.c#22 edit .. //depot/projects/uart/dev/puc/pucvar.h#19 edit Differences ... ==== //depot/projects/uart/dev/puc/puc.c#22 (text+ko) ==== @@ -113,16 +113,17 @@ puc_attach(device_t dev) { struct puc_bar *bar; + struct puc_port *port; struct puc_softc *sc; struct rman *rm; intptr_t res; u_long start; - int error, i, port; + int error, idx; sc = device_get_softc(dev); - for (i = 0; i < PUC_PCI_BARS; i++) - sc->sc_bar[i].b_rid = -1; + for (idx = 0; idx < PUC_PCI_BARS; idx++) + sc->sc_bar[idx].b_rid = -1; sc->sc_ioport.rm_type = RMAN_ARRAY; sc->sc_ioport.rm_descr = "I/O port space"; @@ -143,13 +144,14 @@ sc->sc_port = malloc(sc->sc_nports * sizeof(struct puc_port), M_PUC, M_WAITOK|M_ZERO); - for (port = 0; port < sc->sc_nports; port++) { - sc->sc_port[port].p_nr = port + 1; - error = puc_query(sc->sc_cfg, PUC_QUERY_TYPE, port, &res); + for (idx = 0; idx < sc->sc_nports; idx++) { + port = &sc->sc_port[idx]; + port->p_nr = idx + 1; + error = puc_query(sc->sc_cfg, PUC_QUERY_TYPE, idx, &res); if (error) goto fail; - sc->sc_port[port].p_type = res; - error = puc_query(sc->sc_cfg, PUC_QUERY_RID, port, &res); + port->p_type = res; + error = puc_query(sc->sc_cfg, PUC_QUERY_RID, idx, &res); if (error) goto fail; bar = puc_get_bar(sc, res); @@ -157,19 +159,30 @@ error = ENXIO; goto fail; } - sc->sc_port[port].p_bar = bar; - error = puc_query(sc->sc_cfg, PUC_QUERY_OFS, port, &res); + port->p_bar = bar; + error = puc_query(sc->sc_cfg, PUC_QUERY_OFS, idx, &res); if (error) goto fail; start = rman_get_start(bar->b_res) + res; - error = puc_query(sc->sc_cfg, PUC_QUERY_LEN, port, &res); + error = puc_query(sc->sc_cfg, PUC_QUERY_LEN, idx, &res); if (error) goto fail; rm = (bar->b_type == SYS_RES_IOPORT) ? &sc->sc_ioport: &sc->sc_iomem; - sc->sc_port[port].p_res = rman_reserve_resource(rm, start, + port->p_res = rman_reserve_resource(rm, start, start + res - 1, res, 0, sc->sc_dev); + if (port->p_res == NULL) + continue; + + port->p_dev = device_add_child(dev, NULL, -1); + if (port->p_dev == NULL) { + rman_release_resource(port->p_res); + port->p_res = NULL; + continue; + } + + device_set_ivars(port->p_dev, (void *)port); } sc->sc_irid = 0; @@ -197,17 +210,31 @@ sc->sc_polled = 1; } + /* Probe and attach our children. */ + for (idx = 0; idx < sc->sc_nports; idx++) { + port = &sc->sc_port[idx]; + error = device_probe_and_attach(port->p_dev); + if (error) { + device_delete_child(dev, port->p_dev); + port->p_dev = NULL; + } + } + return (0); fail: - for (port = 0; port < sc->sc_nports; port++) { - if (sc->sc_port[port].p_res != NULL) - rman_release_resource(sc->sc_port[port].p_res); + for (idx = 0; idx < sc->sc_nports; idx++) { + port = &sc->sc_port[idx]; + if (port->p_dev != NULL) + device_delete_child(dev, port->p_dev); + if (port->p_res != NULL) + rman_release_resource(port->p_res); } - for (i = 0; i < PUC_PCI_BARS; i++) { - if (sc->sc_bar[i].b_res != NULL) - bus_release_resource(sc->sc_dev, sc->sc_bar[i].b_type, - sc->sc_bar[i].b_rid, sc->sc_bar[i].b_res); + for (idx = 0; idx < PUC_PCI_BARS; idx++) { + bar = &sc->sc_bar[idx]; + if (bar->b_res != NULL) + bus_release_resource(sc->sc_dev, bar->b_type, + bar->b_rid, bar->b_res); } rman_fini(&sc->sc_iomem); rman_fini(&sc->sc_ioport); ==== //depot/projects/uart/dev/puc/pucvar.h#19 (text+ko) ==== @@ -40,6 +40,7 @@ struct puc_port { struct puc_bar *p_bar; struct resource *p_res; + device_t p_dev; int p_nr; int p_type; int p_rclk;