From nobody Thu Feb 27 14:16:34 2025 X-Original-To: dev-commits-src-all@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 4Z3YLB5j6Dz5qGFL; Thu, 27 Feb 2025 14:16:34 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z3YLB5FGLz3wr3; Thu, 27 Feb 2025 14:16:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740665794; 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=tyFmOywq9/LrA5eC90px5xQyOkD7Fx+nLXL0RplQsUE=; b=X/lwNrG+gpqEJYwdMeo6s5LfNuvQ/m5C5Eewur11NJ6FqSQbns71vSbCxQo6Rb2qSPZrc+ pA3ykLpjxR4EmCRCQ3J8GwI2KcrUlpuLzHOmW+8Oa5trkgZC9hwooFgbENmHzu5+R4KPfY aqnBxJcog/W8fCqS0i2exgZGsglGVBpobcM5+Xq+fb9awJjWA6IdK9xmzFxUj5mC8q6hLq 7a25oW8vAs4NT74rbhyp2M5Zi0r5rf3+bPNhl9wIxExGY3C9ip1cYyITmzWWPfLVLwgpFG km1jDwVy6QxMFGroJlNhGfbzMPjF+YzYq+DuMV64YXHPLdYhTLom/wAMowRAoA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740665794; a=rsa-sha256; cv=none; b=jsROjTyjMxGPmJ1KHl7Hcp5HfixxUx5Igf+l+AEDlQZMKsUmK+GnfAOwA5MZTT4kOWvZhK AQ0f7OIDam099WiiZA21wqDLTWtdq+hewVcDx/+ESglOLLW4lSEhk5JOAD/nkqzMRw3vk2 6p+O60Gwm7q8Lpkx9ik3IguV8MWO/zAL611MuzWqb0CqAvHHVolOtZBvKgN77rCVTOM3/c 3OHLlOlwh9RWq0Dc2MujfHIQnlwIkCXDOeMVA3uiuHrtgG+JQX9qrICChHkek9EzIW/rFg 54Djyp+kXAlL/gBq2IUi9KR9ur7YBdCwWmYu5dWvDxkNVMjZlUgERZHSRbvkZw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740665794; 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=tyFmOywq9/LrA5eC90px5xQyOkD7Fx+nLXL0RplQsUE=; b=rB+OhOkvc45vUplsDECd/nJCyMb/+ta20Dhf4eZhlmGoPgf2gNTH8QO16m4874/TE37/Ux fP5O+rcwg0uhwBtw9Rtfh5CMNMC9rfRLeAVeBZn8AOFuBmXWS/MDS3xbD8VfZvZWa4cwOg cqnaLmEF73XBZhbbXAl7zwDmecVcytilN+l8Ph8cd/ydX8KFAhdA4fIMRUq0AwQY3NbGA6 2l74ERPf+hcSuCgEywkKhMKNj/6AUx1cQBGEy4VZbKX3LhhkZasmbveKsxt6Y6q9njNB/N enjwD8sjzwXDwORUfn1aJSMQ6eBSLekZFZBZlj1kooTHGbAyxZN/aG6Y5DJmqQ== 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 4Z3YLB4cDxzmQD; Thu, 27 Feb 2025 14:16:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51REGYu8015726; Thu, 27 Feb 2025 14:16:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51REGYWT015723; Thu, 27 Feb 2025 14:16:34 GMT (envelope-from git) Date: Thu, 27 Feb 2025 14:16:34 GMT Message-Id: <202502271416.51REGYWT015723@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 326dfed42c7e - stable/14 - powerpc psim: Use bus_generic_rman_* List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 326dfed42c7ead51f63a60424441d332a7444c57 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=326dfed42c7ead51f63a60424441d332a7444c57 commit 326dfed42c7ead51f63a60424441d332a7444c57 Author: John Baldwin AuthorDate: 2024-01-23 17:36:26 +0000 Commit: John Baldwin CommitDate: 2025-02-27 13:09:20 +0000 powerpc psim: Use bus_generic_rman_* - Split out bits of iobus_activate/deactive_resource to implement iobus_map/unmap_resource. - Use bus_generic_rman_* methods in several bus methods to handle memory and I/O port resources. - Add an implementation of bus_adjust_resource. Reviewed by: imp, jhibbits Differential Revision: https://reviews.freebsd.org/D43433 (cherry picked from commit d7c16b333455faef4236d98bb6e671651e87a66d) --- sys/powerpc/psim/iobus.c | 183 +++++++++++++++++++++++++++++++---------------- 1 file changed, 123 insertions(+), 60 deletions(-) diff --git a/sys/powerpc/psim/iobus.c b/sys/powerpc/psim/iobus.c index 4ec0f1664e1c..497ef42d82e6 100644 --- a/sys/powerpc/psim/iobus.c +++ b/sys/powerpc/psim/iobus.c @@ -70,13 +70,21 @@ static int iobus_print_child(device_t dev, device_t child); static void iobus_probe_nomatch(device_t, device_t); static int iobus_read_ivar(device_t, device_t, int, uintptr_t *); static int iobus_write_ivar(device_t, device_t, int, uintptr_t); +static struct rman *iobus_get_rman(device_t, int, u_int); static struct resource *iobus_alloc_resource(device_t, device_t, int, int *, rman_res_t, rman_res_t, rman_res_t, u_int); +static int iobus_adjust_resource(device_t, device_t, int, struct resource *, + rman_res_t, rman_res_t); static int iobus_activate_resource(device_t, device_t, int, int, struct resource *); static int iobus_deactivate_resource(device_t, device_t, int, int, struct resource *); +static int iobus_map_resource(device_t, device_t, int, struct resource *, + struct resource_map_request *, + struct resource_map *); +static int iobus_unmap_resource(device_t, device_t, int, struct resource *, + struct resource_map *); static int iobus_release_resource(device_t, device_t, int, int, struct resource *); @@ -100,10 +108,14 @@ static device_method_t iobus_methods[] = { DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), + DEVMETHOD(bus_get_rman, iobus_get_rman), DEVMETHOD(bus_alloc_resource, iobus_alloc_resource), + DEVMETHOD(bus_adjust_resource, iobus_adjust_resource), DEVMETHOD(bus_release_resource, iobus_release_resource), DEVMETHOD(bus_activate_resource, iobus_activate_resource), DEVMETHOD(bus_deactivate_resource, iobus_deactivate_resource), + DEVMETHOD(bus_map_resource, iobus_map_resource), + DEVMETHOD(bus_unmap_resource, iobus_unmap_resource), { 0, 0 } }; @@ -293,26 +305,32 @@ iobus_write_ivar(device_t dev, device_t child, int which, uintptr_t value) return (EINVAL); } -static struct resource * -iobus_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) +static struct rman * +iobus_get_rman(device_t bus, int type, u_int flags) { struct iobus_softc *sc; - int needactivate; - struct resource *rv; - struct rman *rm; sc = device_get_softc(bus); + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (&sc->sc_mem_rman); + default: + return (NULL); + } +} - needactivate = flags & RF_ACTIVE; - flags &= ~RF_ACTIVE; +static struct resource * +iobus_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) +{ switch (type) { case SYS_RES_MEMORY: case SYS_RES_IOPORT: - rm = &sc->sc_mem_rman; - break; + return (bus_generic_rman_alloc_resource(bus, child, type, rid, + start, end, count, flags)); case SYS_RES_IRQ: return (bus_alloc_resource(bus, type, rid, start, end, count, flags)); @@ -321,80 +339,125 @@ iobus_alloc_resource(device_t bus, device_t child, int type, int *rid, device_get_nameunit(child)); return (NULL); } +} - rv = rman_reserve_resource(rm, start, end, count, flags, child); - if (rv == NULL) { - device_printf(bus, "failed to reserve resource for %s\n", - device_get_nameunit(child)); - return (NULL); - } - - rman_set_rid(rv, *rid); - - if (needactivate) { - if (bus_activate_resource(child, type, *rid, rv) != 0) { - device_printf(bus, - "failed to activate resource for %s\n", - device_get_nameunit(child)); - rman_release_resource(rv); - return (NULL); - } - } +static int +iobus_adjust_resource(device_t bus, device_t child, int type, + struct resource *r, rman_res_t start, rman_res_t end) +{ - return (rv); + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_adjust_resource(bus, child, type, r, + start, end)); + case SYS_RES_IRQ: + return (bus_adjust_resource(bus, type, r, start, end)); + default: + return (EINVAL); + } } static int iobus_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { - if (rman_get_flags(res) & RF_ACTIVE) { - int error = bus_deactivate_resource(child, type, rid, res); - if (error) - return error; - } - return (rman_release_resource(res)); + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_release_resource(bus, child, type, rid, + res)); + case SYS_RES_IRQ: + return (bus_release_resource(bus, type, rid, res)); + default: + return (EINVAL); + } } static int iobus_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { - struct iobus_softc *sc; - void *p; - - sc = device_get_softc(bus); - if (type == SYS_RES_IRQ) + switch (type) { + case SYS_RES_IRQ: return (bus_activate_resource(bus, type, rid, res)); - - if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) { - p = pmap_mapdev((vm_paddr_t)rman_get_start(res) + sc->sc_addr, - (vm_size_t)rman_get_size(res)); - if (p == NULL) - return (ENOMEM); - rman_set_virtual(res, p); - rman_set_bustag(res, &bs_le_tag); - rman_set_bushandle(res, (u_long)p); + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + return (bus_generic_rman_activate_resource(bus, child, type, + rid, res)); + default: + return (EINVAL); } - - return (rman_activate_resource(res)); } static int iobus_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { - /* - * If this is a memory resource, unmap it. - */ - if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) { - u_int32_t psize; - psize = rman_get_size(res); - pmap_unmapdev(rman_get_virtual(res), psize); + switch (type) { + case SYS_RES_IRQ: + return (bus_deactivate_resource(bus, type, rid, res)); + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + return (bus_generic_rman_deactivate_resource(bus, child, type, + rid, res)); + default: + return (EINVAL); } +} - return (rman_deactivate_resource(res)); +static int +iobus_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; + struct iobus_softc *sc; + 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); + + sc = device_get_softc(bus); + map->r_vaddr = pmap_mapdev_attr((vm_paddr_t)start + sc->sc_addr, + (vm_size_t)length, args.memattr); + if (map->r_vaddr == NULL) + return (ENOMEM); + map->r_bustag = &bs_le_tag; + map->r_bushandle = (vm_offset_t)map->r_vaddr; + map->r_size = length; + return (0); +} + +static int +iobus_unmap_resource(device_t bus, device_t child, int type, struct resource *r, + struct resource_map *map) +{ + + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + pmap_unmapdev(map->r_vaddr, map->r_size); + return (0); + default: + return (EINVAL); + } }