From owner-p4-projects@FreeBSD.ORG Fri Aug 3 17:35:27 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9344616A41F; Fri, 3 Aug 2007 17:35:27 +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 5FF2616A41A for ; Fri, 3 Aug 2007 17:35:27 +0000 (UTC) (envelope-from thioretic@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 564CA13C4D9 for ; Fri, 3 Aug 2007 17:35:27 +0000 (UTC) (envelope-from thioretic@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l73HZRtx044720 for ; Fri, 3 Aug 2007 17:35:27 GMT (envelope-from thioretic@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l73HZQ3E044717 for perforce@freebsd.org; Fri, 3 Aug 2007 17:35:26 GMT (envelope-from thioretic@FreeBSD.org) Date: Fri, 3 Aug 2007 17:35:26 GMT Message-Id: <200708031735.l73HZQ3E044717@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to thioretic@FreeBSD.org using -f From: Maxim Zhuravlev To: Perforce Change Reviews Cc: Subject: PERFORCE change 124603 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: Fri, 03 Aug 2007 17:35:27 -0000 http://perforce.freebsd.org/chv.cgi?CH=124603 Change 124603 by thioretic@thioretic on 2007/08/03 17:35:24 if root_bus was set to be parent of a persistent device, when the latest was orphaned, on add_parent() remove root_bus from parents. add protos to bus.h Affected files ... .. //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#24 edit .. //depot/projects/soc2007/thioretic_gidl/sys/bus.h#8 edit Differences ... ==== //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#24 (text+ko) ==== @@ -182,6 +182,8 @@ typedef struct devicelink* devicelink_t; struct devicelink { device_t device_ptr; +#define DLF_ANCHOR 1 + int flags; TAILQ(devicelink) link; }; @@ -2168,21 +2170,21 @@ static int device_add_to_dev_list (device_t addwhat, devicelink_list_t *addwhere, int incr_refs){ - devicelink_t pd; + devicelink_t dl; - TAILQ_FOREACH (pd, addwhere, link){ - if (pd->device_ptr == addwhat) + TAILQ_FOREACH (dl, addwhere, link){ + if (dl->device_ptr == addwhat) return (1); } - pd = malloc(sizeof(struct devicelink), M_BUS, M_NOWAIT|M_ZERO); - if (!pd) + dl = malloc(sizeof(struct devicelink), M_BUS, M_NOWAIT|M_ZERO); + if (!dl) return (0); - pd->device_ptr = addwhat; - TAILQ_INSERT_TAIL(addwhere, pd, link); + dl->device_ptr = addwhat; + TAILQ_INSERT_TAIL(addwhere, dl, link); if (incr_refs) - pd->device_ptr->refs++; + dl->device_ptr->refs++; bus_data_generation_update(); return (1); @@ -2205,7 +2207,17 @@ */ int device_add_existing_parent (device_t dev, device_t parent){ + int count = 0; + devicelink_t dl; + device_add_to_dev_list (parent, &dev->parents, FALSE); + + TAILQ_FOREACH (dl, &dev->parents, link){count++;} + if ((count == 2) && (dl = TAILQ_FIRST(&dev->parents)) && + (dl->flags & DLF_ANCHOR) && (dl->device_ptr == root_bus)){ + device_delete_existing_parent (dev, root_bus); + } + device_add_to_dev_list (dev, &parent->children, TRUE); } @@ -2268,7 +2280,7 @@ child->device_ptr->refs++; device_add_existing_parent (child->device_ptr, dev); - + bus_data_generation_update(); return (child); } @@ -2290,7 +2302,7 @@ return (destroy_recurse (devtodel, dev, CHILDREN)); /* remove children first */ - if (devtodel->refs > 1) goto deletefromparents; + if (devtodel->refs > 1) goto deletefromparent; while ( (grand = TAILQ_FIRST(&devtodel->children)) ) { error = destroy_recurse(devtodel, grand->device_ptr, direction); if (error) @@ -2303,7 +2315,7 @@ return (error); if (devtodel->devclass) devclass_delete_device(devtodel->devclass, devtodel); -deletefromparents: +deletefromparent: TAILQ_FOREACH_SAFE(pd, &devtodel->parents, link, pd2){ if (pd->device_ptr == dev){ TAILQ_REMOVE(&devtodel->parents, pd, link); @@ -2313,8 +2325,10 @@ } } - if (devtodel->flags & DF_PERSISTENT){ + if (!devtodel->refs && (devtodel->flags & DF_PERSISTENT)){ device_add_existing_parent(dev, root_bus); + pd = TAILQ_FIRST(&dev->parents); + pd->flags |= DLF_ANCHOR; return (0); } @@ -2329,14 +2343,14 @@ } -void +int device_delete_existing_child (device_t dev, device_t child){ - destroy_recurse (dev, child, CHILDREN); + return (destroy_recurse (dev, child, CHILDREN)); } -void +int device_delete_existing_parent (device_t dev, device_t parent){ - destroy_recurse (dev, parent, PARENTS); + return (destroy_recurse (dev, parent, PARENTS)); } /** @@ -2394,7 +2408,7 @@ * @returns the device with the given unit number or @c * NULL if there is no such device */ -device_t +static device_t device_find_relation(device_t dev, const char *classname, int unit, int direction) { devclass_t dc; @@ -2630,7 +2644,7 @@ * @retval 0 success * @retval ENOMEM the array allocation failed */ -int +static int device_get_relations(device_t dev, device_t **devlistp, int *devcountp, int direction) { int count; ==== //depot/projects/soc2007/thioretic_gidl/sys/bus.h#8 (text+ko) ==== @@ -341,27 +341,38 @@ * Access functions for device. */ device_t device_add_child(device_t dev, const char *name, int unit); +int device_add_existing_child (device_t dev, device_t child); +int device_add_existing_parent (device_t dev, device_t parent); device_t device_add_child_ordered(device_t dev, int order, const char *name, int unit); void device_busy(device_t dev); int device_delete_child(device_t dev, device_t child); +int device_delete_existing_child (device_t dev, device_t child); +int device_delete_existing_parent (device_t dev, device_t parent); int device_attach(device_t dev); int device_detach(device_t dev); void device_disable(device_t dev); void device_enable(device_t dev); device_t device_find_child(device_t dev, const char *classname, int unit); +device_t device_find_parent(device_t dev, const char* classname, + int unit); const char *device_get_desc(device_t dev); devclass_t device_get_devclass(device_t dev); driver_t *device_get_driver(device_t dev); u_int32_t device_get_flags(device_t dev); device_t device_get_parent(device_t dev); int device_get_children(device_t dev, device_t **listp, int *countp); +int device_get_all_parents(device_t dev, device_t **listp, int *countp); void *device_get_ivars(device_t dev); +void *device_get_driver_ivars (device_t dev, driver_t *driver); void device_set_ivars(device_t dev, void *ivars); +void device_set_driver_ivars (device_t dev, driver_t *driver, + void* ivars); const char *device_get_name(device_t dev); const char *device_get_nameunit(device_t dev); void *device_get_softc(device_t dev); +void *device_get_driver_softc(device_t dev, driver_t *driver); device_state_t device_get_state(device_t dev); int device_get_unit(device_t dev); struct sysctl_ctx_list *device_get_sysctl_ctx(device_t dev); @@ -381,6 +392,8 @@ int device_set_driver(device_t dev, driver_t *driver); void device_set_flags(device_t dev, u_int32_t flags); void device_set_softc(device_t dev, void *softc); +void device_set_driver_softc(device_t dev, driver_t *driver, + void* softc); int device_set_unit(device_t dev, int unit); /* XXX DONT USE XXX */ int device_shutdown(device_t dev); void device_unbusy(device_t dev); @@ -397,6 +410,8 @@ const char *devclass_get_name(devclass_t dc); device_t devclass_get_device(devclass_t dc, int unit); void *devclass_get_softc(devclass_t dc, int unit); +void *devclass_get_driver_softc (devclass_t dc, int unit, driver_t *driver); + int devclass_get_devices(devclass_t dc, device_t **listp, int *countp); int devclass_get_drivers(devclass_t dc, driver_t ***listp, int *countp); int devclass_get_count(devclass_t dc);