From owner-svn-src-all@FreeBSD.ORG Sat May 9 03:05:46 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 195B4264; Sat, 9 May 2015 03:05:46 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 06B3715FA; Sat, 9 May 2015 03:05:46 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t4935j4h086986; Sat, 9 May 2015 03:05:45 GMT (envelope-from loos@FreeBSD.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t4935jYk086983; Sat, 9 May 2015 03:05:45 GMT (envelope-from loos@FreeBSD.org) Message-Id: <201505090305.t4935jYk086983@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: loos set sender to loos@FreeBSD.org using -f From: Luiz Otavio O Souza Date: Sat, 9 May 2015 03:05:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r282674 - in head/sys/dev: iicbus ofw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 May 2015 03:05:46 -0000 Author: loos Date: Sat May 9 03:05:44 2015 New Revision: 282674 URL: https://svnweb.freebsd.org/changeset/base/282674 Log: Handle IRQ resources on iicbus and ofw_iicbus. Based on a patch submitted by Michal Meloun . Modified: head/sys/dev/iicbus/iicbus.c head/sys/dev/iicbus/iicbus.h head/sys/dev/ofw/ofw_iicbus.c Modified: head/sys/dev/iicbus/iicbus.c ============================================================================== --- head/sys/dev/iicbus/iicbus.c Sat May 9 00:48:44 2015 (r282673) +++ head/sys/dev/iicbus/iicbus.c Sat May 9 03:05:44 2015 (r282674) @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -147,6 +148,7 @@ iicbus_print_child(device_t dev, device_ retval += bus_print_child_header(dev, child); if (devi->addr != 0) retval += printf(" at addr %#x", devi->addr); + resource_list_print_type(&devi->rl, "irq", SYS_RES_IRQ, "%ld"); retval += bus_print_child_footer(dev, child); return (retval); @@ -157,9 +159,9 @@ iicbus_probe_nomatch(device_t bus, devic { struct iicbus_ivar *devi = IICBUS_IVAR(child); - device_printf(bus, ""); - printf(" at addr %#x\n", devi->addr); - return; + device_printf(bus, " at addr %#x", devi->addr); + resource_list_print_type(&devi->rl, "irq", SYS_RES_IRQ, "%ld"); + printf("\n"); } static int @@ -209,6 +211,7 @@ iicbus_add_child(device_t dev, u_int ord device_delete_child(dev, child); return (0); } + resource_list_init(&devi->rl); device_set_ivars(child, devi); return (child); } @@ -217,11 +220,77 @@ static void iicbus_hinted_child(device_t bus, const char *dname, int dunit) { device_t child; + int irq; struct iicbus_ivar *devi; child = BUS_ADD_CHILD(bus, 0, dname, dunit); devi = IICBUS_IVAR(child); resource_int_value(dname, dunit, "addr", &devi->addr); + if (resource_int_value(dname, dunit, "irq", &irq) == 0) { + if (bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1) != 0) + device_printf(bus, + "warning: bus_set_resource() failed\n"); + } +} + +static int +iicbus_set_resource(device_t dev, device_t child, int type, int rid, + u_long start, u_long count) +{ + struct iicbus_ivar *devi; + struct resource_list_entry *rle; + + devi = IICBUS_IVAR(child); + rle = resource_list_add(&devi->rl, type, rid, start, + start + count - 1, count); + if (rle == NULL) + return (ENXIO); + + return (0); +} + +static struct resource * +iicbus_alloc_resource(device_t bus, device_t child, int type, int *rid, + u_long start, u_long end, u_long count, u_int flags) +{ + struct resource_list *rl; + struct resource_list_entry *rle; + + /* Only IRQ resources are supported. */ + if (type != SYS_RES_IRQ) + return (NULL); + + /* + * Request for the default allocation with a given rid: use resource + * list stored in the local device info. + */ + if ((start == 0UL) && (end == ~0UL)) { + rl = BUS_GET_RESOURCE_LIST(bus, child); + if (rl == NULL) + return (NULL); + rle = resource_list_find(rl, type, *rid); + if (rle == NULL) { + if (bootverbose) + device_printf(bus, "no default resources for " + "rid = %d, type = %d\n", *rid, type); + return (NULL); + } + start = rle->start; + end = rle->end; + count = rle->count; + } + + return (bus_generic_alloc_resource(bus, child, type, rid, start, end, + count, flags)); +} + +static struct resource_list * +iicbus_get_resource_list(device_t bus __unused, device_t child) +{ + struct iicbus_ivar *devi; + + devi = IICBUS_IVAR(child); + return (&devi->rl); } int @@ -297,6 +366,16 @@ static device_method_t iicbus_methods[] DEVMETHOD(device_detach, iicbus_detach), /* bus interface */ + DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), + DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), + DEVMETHOD(bus_release_resource, bus_generic_release_resource), + DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), + DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), + DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource), + DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), + DEVMETHOD(bus_alloc_resource, iicbus_alloc_resource), + DEVMETHOD(bus_get_resource_list, iicbus_get_resource_list), + DEVMETHOD(bus_set_resource, iicbus_set_resource), DEVMETHOD(bus_add_child, iicbus_add_child), DEVMETHOD(bus_print_child, iicbus_print_child), DEVMETHOD(bus_probe_nomatch, iicbus_probe_nomatch), Modified: head/sys/dev/iicbus/iicbus.h ============================================================================== --- head/sys/dev/iicbus/iicbus.h Sat May 9 00:48:44 2015 (r282673) +++ head/sys/dev/iicbus/iicbus.h Sat May 9 03:05:44 2015 (r282674) @@ -50,6 +50,7 @@ struct iicbus_softc struct iicbus_ivar { uint32_t addr; + struct resource_list rl; bool nostop; }; Modified: head/sys/dev/ofw/ofw_iicbus.c ============================================================================== --- head/sys/dev/ofw/ofw_iicbus.c Sat May 9 00:48:44 2015 (r282673) +++ head/sys/dev/ofw/ofw_iicbus.c Sat May 9 03:05:44 2015 (r282674) @@ -50,6 +50,8 @@ static device_t ofw_iicbus_add_child(dev const char *name, int unit); static const struct ofw_bus_devinfo *ofw_iicbus_get_devinfo(device_t bus, device_t dev); +static struct resource_list *ofw_iicbus_get_resource_list(device_t bus, + device_t child); static device_method_t ofw_iicbus_methods[] = { /* Device interface */ @@ -57,6 +59,7 @@ static device_method_t ofw_iicbus_method DEVMETHOD(device_attach, ofw_iicbus_attach), /* Bus interface */ + DEVMETHOD(bus_get_resource_list, ofw_iicbus_get_resource_list), DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str), DEVMETHOD(bus_add_child, ofw_iicbus_add_child), @@ -72,7 +75,7 @@ static device_method_t ofw_iicbus_method }; struct ofw_iicbus_devinfo { - struct iicbus_ivar opd_dinfo; + struct iicbus_ivar opd_dinfo; /* Must be the first. */ struct ofw_bus_devinfo opd_obdinfo; }; @@ -153,7 +156,10 @@ ofw_iicbus_attach(device_t dev) free(dinfo, M_DEVBUF); continue; } + childdev = device_add_child(dev, NULL, -1); + resource_list_init(&dinfo->opd_dinfo.rl); + ofw_bus_intr_to_rl(childdev, child, &dinfo->opd_dinfo.rl); device_set_ivars(childdev, dinfo); } @@ -199,3 +205,12 @@ ofw_iicbus_get_devinfo(device_t bus, dev dinfo = device_get_ivars(dev); return (&dinfo->opd_obdinfo); } + +static struct resource_list * +ofw_iicbus_get_resource_list(device_t bus __unused, device_t child) +{ + struct ofw_iicbus_devinfo *devi; + + devi = device_get_ivars(child); + return (&devi->opd_dinfo.rl); +}