From nobody Tue Jan 23 17:45:56 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TKDys0HX5z57mYX; Tue, 23 Jan 2024 17:45:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TKDyr3b9Sz47Cr; Tue, 23 Jan 2024 17:45:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QUYMPhjmJWrRW5O/VpWni2fKymBx7POBIrz3jtzv8R4=; b=wqf/WP9lWw98Uem4GADKW/HW6FQ5Bz5Dm9ahM8vpBwGWDv1HZxjBBhQV0EKTIl7saCIP5d t3Jq+zSRCqvo1ApqYgHi3X7xYVe+UMLoxbbH9d4z9tp9poZtooms1yKj9hAPgVOy1O15oe fSitzFHP71KPbin+rR/n+bG4KFj4trsB8iTq3mKfUOZxuDgHS7OS3Zrjy03K2lNmTVOBaN mG5ZTAt+8UE0XQWnBajKzfvCNbVM7F1Oh4sVngp+zYq2HbrOMQtXqhjdyA/S/rYHGbB5gI N2ebY/jYmPNMRMemNLGFEvNoeWJw6Ufwa39SHMLhOjoWQ2IZ5uqycbRlpHoikw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QUYMPhjmJWrRW5O/VpWni2fKymBx7POBIrz3jtzv8R4=; b=TJ5B3l96gHWY42QR6KR1Ud8+o9+RTJ3RDBB4mm5t6GbFMs0Nee7nv5J7UPGymoK0a2M6sW 6EPwEoLbeZfe77Beh2VVlyB3z5Lpmoo4Z6kP74QszPtMKZAN6cvyIzFWJYtpm7oNoPa0vO ZpCN5mmIAMNx5NptJ/W0N9Ay1kyAijt4sc66QOtapqAZEnETA01BwLwBKLSugp6+V18S6W BOqrGqNsQvX9bhf9zwJOPgtB7J4UsqomMduap7mgESGkcGu5Zadawu+/uj1MKOsWOiUwNB gA1CfofWrOs+CMGYwRBOrfFYvTESSQbJFCMDzIjPZ1OKj+DQuJEK8ENbP2wG6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706031956; a=rsa-sha256; cv=none; b=ZqVvfDChc3oNPOaqPxiADJGIzRBeYZ+TPReRNqbarvU+4ZEpr9QtRI1T9wkv9gzgrspuqS HSwBRUwXKI+vOJUtV33q3B0CnOjzUlDNNP5wsG7kTRuUP4Sos17HAZJElJksSVHJXvreZL /ShqlCCZXgusq6ltKeIsGhlkBd3Gkj/NVO01PcZWW3cEYNXZs+jhdTbKDDnQ1a44EwJfFa +RY5+meARwe5OC3LSKu64hUmKnkH02/2ZovKtpVKIBOgnJVyvprCqBoZaELk9Oi5wG2mlz 9ZLVrJ+HTY3tNgG8sGb+E1UKFzODh3+bbKrD8kbqZzO74ykpd2d+pit9QwXHSQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TKDyr2gY3zfpR; Tue, 23 Jan 2024 17:45:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40NHjuAZ075830; Tue, 23 Jan 2024 17:45:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40NHjuu0075827; Tue, 23 Jan 2024 17:45:56 GMT (envelope-from git) Date: Tue, 23 Jan 2024 17:45:56 GMT Message-Id: <202401231745.40NHjuu0075827@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 5a7e717fb790 - main - powerpc mpc85xx: Use bus_generic_rman_* List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5a7e717fb790842eddf766363d337ec879b3b513 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=5a7e717fb790842eddf766363d337ec879b3b513 commit 5a7e717fb790842eddf766363d337ec879b3b513 Author: John Baldwin AuthorDate: 2024-01-23 17:36:37 +0000 Commit: John Baldwin CommitDate: 2024-01-23 17:36:37 +0000 powerpc mpc85xx: Use bus_generic_rman_* - Consistently map SYS_RES_IOPORT to SYS_RES_MEMORY for bus_activate/deactivate/adjust/release_resource. - Implement bus_map/unmap_resource. - Add an implementation of bus_adjust_resource. Reviewed by: jhibbits Differential Revision: https://reviews.freebsd.org/D43434 --- sys/powerpc/mpc85xx/lbc.c | 185 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 137 insertions(+), 48 deletions(-) diff --git a/sys/powerpc/mpc85xx/lbc.c b/sys/powerpc/mpc85xx/lbc.c index c07fa1251b2c..7db2d49955a3 100644 --- a/sys/powerpc/mpc85xx/lbc.c +++ b/sys/powerpc/mpc85xx/lbc.c @@ -69,13 +69,20 @@ static MALLOC_DEFINE(M_LBC, "localbus", "localbus devices information"); static int lbc_probe(device_t); static int lbc_attach(device_t); static int lbc_shutdown(device_t); -static int lbc_activate_resource(device_t bus __unused, device_t child __unused, - int type, int rid __unused, struct resource *r); -static int lbc_deactivate_resource(device_t bus __unused, - device_t child __unused, int type __unused, int rid __unused, +static int lbc_map_resource(device_t, device_t, int, struct resource *, + struct resource_map_request *, struct resource_map *); +static int lbc_unmap_resource(device_t, device_t, int, struct resource *, + struct resource_map *map); +static int lbc_activate_resource(device_t bus, device_t child, + int type, int rid, struct resource *r); +static int lbc_deactivate_resource(device_t bus, + device_t child, int type __unused, int rid, struct resource *r); +static struct rman *lbc_get_rman(device_t, int, u_int); static struct resource *lbc_alloc_resource(device_t, device_t, int, int *, rman_res_t, rman_res_t, rman_res_t, u_int); +static int lbc_adjust_resource(device_t, device_t, int, struct resource *, + rman_res_t, rman_res_t); static int lbc_print_child(device_t, device_t); static int lbc_release_resource(device_t, device_t, int, int, struct resource *); @@ -95,10 +102,14 @@ static device_method_t lbc_methods[] = { DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, NULL), + DEVMETHOD(bus_get_rman, lbc_get_rman), DEVMETHOD(bus_alloc_resource, lbc_alloc_resource), + DEVMETHOD(bus_adjust_resource, lbc_adjust_resource), DEVMETHOD(bus_release_resource, lbc_release_resource), DEVMETHOD(bus_activate_resource, lbc_activate_resource), DEVMETHOD(bus_deactivate_resource, lbc_deactivate_resource), + DEVMETHOD(bus_map_resource, lbc_map_resource), + DEVMETHOD(bus_unmap_resource, lbc_unmap_resource), /* OFW bus interface */ DEVMETHOD(ofw_bus_get_devinfo, lbc_get_devinfo), @@ -672,22 +683,31 @@ lbc_shutdown(device_t dev) return(0); } +static struct rman * +lbc_get_rman(device_t bus, int type, u_int flags) +{ + struct lbc_softc *sc; + + sc = device_get_softc(bus); + switch (type) { + case SYS_RES_MEMORY: + return (&sc->sc_rman); + default: + return (NULL); + } +} + static struct resource * lbc_alloc_resource(device_t bus, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) { - struct lbc_softc *sc; struct lbc_devinfo *di; struct resource_list_entry *rle; - struct resource *res; - struct rman *rm; - int needactivate; /* We only support default allocations. */ if (!RMAN_IS_DEFAULT_RANGE(start, end)) return (NULL); - sc = device_get_softc(bus); if (type == SYS_RES_IRQ) return (bus_alloc_resource(bus, type, rid, start, end, count, flags)); @@ -702,6 +722,10 @@ lbc_alloc_resource(device_t bus, device_t child, int type, int *rid, if (type == SYS_RES_IOPORT) type = SYS_RES_MEMORY; + /* + * XXX: We are supposed to return a value to the user, so this + * doesn't seem right. + */ rid = &di->di_bank; rle = resource_list_find(&di->di_res, type, *rid); @@ -714,32 +738,8 @@ lbc_alloc_resource(device_t bus, device_t child, int type, int *rid, count = rle->count; end = start + count - 1; - sc = device_get_softc(bus); - - needactivate = flags & RF_ACTIVE; - flags &= ~RF_ACTIVE; - - rm = &sc->sc_rman; - - res = rman_reserve_resource(rm, start, end, count, flags, child); - if (res == NULL) { - device_printf(bus, "failed to reserve resource %#jx - %#jx " - "(%#jx)\n", start, end, count); - return (NULL); - } - - rman_set_rid(res, *rid); - rman_set_bustag(res, &bs_be_tag); - rman_set_bushandle(res, rman_get_start(res)); - - if (needactivate) - if (bus_activate_resource(child, type, *rid, res)) { - device_printf(child, "resource activation failed\n"); - rman_release_resource(res); - return (NULL); - } - - return (res); + return (bus_generic_rman_alloc_resource(bus, child, type, rid, start, + end, count, flags)); } static int @@ -761,36 +761,125 @@ lbc_print_child(device_t dev, device_t child) return (rv); } +static int +lbc_adjust_resource(device_t dev, device_t child, int type, struct resource *r, + rman_res_t start, rman_res_t end) +{ + switch (type) { + case SYS_RES_IOPORT: + type = SYS_RES_MEMORY; + /* FALLTHROUGH */ + case SYS_RES_MEMORY: + return (bus_generic_rman_adjust_resource(dev, child, type, r, + start, end)); + case SYS_RES_IRQ: + return (bus_adjust_resource(dev, type, r, start, end)); + default: + return (EINVAL); + } +} + static int lbc_release_resource(device_t dev, device_t child, int type, int rid, struct resource *res) { - int err; + switch (type) { + case SYS_RES_IOPORT: + type = SYS_RES_MEMORY; + /* FALLTHROUGH */ + case SYS_RES_MEMORY: + return (bus_generic_rman_release_resource(dev, child, type, + rid, res)); + case SYS_RES_IRQ: + return (bus_release_resource(dev, type, rid, res)); + default: + return (EINVAL); + } +} - if (rman_get_flags(res) & RF_ACTIVE) { - err = bus_deactivate_resource(child, type, rid, res); - if (err) - return (err); +static int +lbc_activate_resource(device_t bus, device_t child, int type, int rid, + struct resource *r) +{ + switch (type) { + case SYS_RES_IOPORT: + type = SYS_RES_MEMORY; + /* FALLTHROUGH */ + case SYS_RES_MEMORY: + return (bus_generic_rman_activate_resource(bus, child, type, + rid, r)); + case SYS_RES_IRQ: + return (bus_activate_resource(bus, type, rid, r)); + default: + return (EINVAL); } +} - return (rman_release_resource(res)); +static int +lbc_deactivate_resource(device_t bus, device_t child, int type, int rid, + struct resource *r) +{ + switch (type) { + case SYS_RES_IOPORT: + type = SYS_RES_MEMORY; + /* FALLTHROUGH */ + case SYS_RES_MEMORY: + return (bus_generic_rman_deactivate_resource(bus, child, type, + rid, r)); + case SYS_RES_IRQ: + return (bus_deactivate_resource(bus, type, rid, r)); + default: + return (EINVAL); + } } static int -lbc_activate_resource(device_t bus __unused, device_t child __unused, - int type __unused, int rid __unused, struct resource *r) +lbc_map_resource(device_t bus, device_t child, int type, struct resource *r, + struct resource_map_request *argsp, struct resource_map *map) { + struct resource_map_request args; + rman_res_t length, start; + int error; + + /* Resources must be active to be mapped. */ + if (!(rman_get_flags(r) & RF_ACTIVE)) + return (ENXIO); + + /* Mappings are only supported on I/O and memory resources. */ + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + break; + default: + return (EINVAL); + } + + resource_init_map_request(&args); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); - /* Child resources were already mapped, just activate. */ - return (rman_activate_resource(r)); + map->r_bustag = &bs_be_tag; + map->r_bushandle = start; + map->r_size = length; + map->r_vaddr = NULL; + return (0); } static int -lbc_deactivate_resource(device_t bus __unused, device_t child __unused, - int type __unused, int rid __unused, struct resource *r) +lbc_unmap_resource(device_t bus, device_t child, int type, struct resource *r, + struct resource_map *map) { - return (rman_deactivate_resource(r)); + /* Mappings are only supported on I/O and memory resources. */ + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + break; + default: + return (EINVAL); + } + return (0); } static const struct ofw_bus_devinfo *