From nobody Tue Jan 23 17:45:54 2024 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 4TKDyp3hMNz57mnv; Tue, 23 Jan 2024 17:45:54 +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 4TKDyp1pWRz46xC; Tue, 23 Jan 2024 17:45:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031954; 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=5CQH0nN24wQ66mEi0QEgkMHdXjOpj8L0xiM3yB7zDGs=; b=WezmPq4+yXE+6kgBj+9QM3Losprtm08dT26gLXBZfCMLJnLnvjL8c2YZJt8+0uzhxBXFDi 860sVYQkQy0yEIPFpVMpGI+CrIh02dkkVQyRv1PUHfHFvcaSK6EB8UOldSC50fU0p7kuwC bMr0tY76sfMfnk65IqSc3kqf/ZeFLEI8/T4V34qG6lowvxNkvIVCoQi0HNshifyuOWprHw 9P7bmF5zhvaEGk2ZPbuqOUh0Bi3lb4XjKIk3+4CRO/cNsx+gSu4tcY3GqtcKk37zRvCTuY 7vUhpG0YRRZvviHZshrGutVrPx4bBuKn7N0K5m5sWqbDTiPLjEECYv4ad4BnqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031954; 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=5CQH0nN24wQ66mEi0QEgkMHdXjOpj8L0xiM3yB7zDGs=; b=SQTPJL/DhD9YsFe+3ohQ0Jf+6lIz4AYeegEv2Hckael36vmWIH71l4dqdkCCKx3w80RiqM DZd3Iv9Mw3738pgLYWgl8xZYyBwuUMdCme+cRQuJXHLrjlKMOucYmHNhjQFl8roFVFQUEh Sw6DCQ2fHNpnWCrAablAOvX2ieMJO2AwHjrIpvXdGP39fXSJ9j1pEdEwmFkJBgy4iaimU+ PJdnk/HxYy0J7Rxq5QY+8ttacn6gTM9t6x9RNryzWiEE5P5yBD7IdJRBOPqtBNms/573W2 LTwjqzLK0wfdwae8i12v8lHMQ94sk29l1m4KOQ9GjpheOCQihGEDrZ3tH7J1nA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706031954; a=rsa-sha256; cv=none; b=j9XmxISwhjjaOl4/EDDe5b3/+PzWctgZlHcxpHXgUile75YbmGZxFYmCbXwaNVEKZubHvC ahpuvb3hUnfsXOMYk0rx4NVsPg+WTGinK51UVwEdf+tLA0oQz3SFBGQ47tNc7nATAAn4J0 Vghuxgcyh7iTH1fKHf+qrdNZShUkiK0BhPDrcvwPeO3U78fZAqC1xIV9Vl60StpI/IGfOV E5H/CwwTvH4Qg58S3/gbZsJWDU183636FvLRYqMGd4rVuNigDgxYFEMiIr3EG851TG/3ac sg8c7hAKM7+Xl4t2/Gb3GhxqV9II/E67oUyTZyipB3k39kBZB13Zbb8H7tU2ug== 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 4TKDyp0vlfzfpQ; Tue, 23 Jan 2024 17:45:54 +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 40NHjsNN075745; Tue, 23 Jan 2024 17:45:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40NHjssP075742; Tue, 23 Jan 2024 17:45:54 GMT (envelope-from git) Date: Tue, 23 Jan 2024 17:45:54 GMT Message-Id: <202401231745.40NHjssP075742@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: 3dd55df98282 - main - powerpc ps3bus: 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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/main X-Git-Reftype: branch X-Git-Commit: 3dd55df98282293c41bb0d98fa54312a9cf2aba5 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=3dd55df98282293c41bb0d98fa54312a9cf2aba5 commit 3dd55df98282293c41bb0d98fa54312a9cf2aba5 Author: John Baldwin AuthorDate: 2024-01-23 17:36:12 +0000 Commit: John Baldwin CommitDate: 2024-01-23 17:36:12 +0000 powerpc ps3bus: Use bus_generic_rman_* - Split out part of ps3bus_activate_resource into a ps3bus_map_resource method. - Implement ps3bus_unmap_resource via pmap_unmapdev. - Use bus_generic_rman_* to add bus_adjust_resource, bus_deactivate_resource, and bus_release_resource methods. Reviewed by: imp, jhibbits Differential Revision: https://reviews.freebsd.org/D43432 --- sys/powerpc/ps3/ps3bus.c | 130 +++++++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 56 deletions(-) diff --git a/sys/powerpc/ps3/ps3bus.c b/sys/powerpc/ps3/ps3bus.c index 64548e5a3b34..c3f46d4942ad 100644 --- a/sys/powerpc/ps3/ps3bus.c +++ b/sys/powerpc/ps3/ps3bus.c @@ -57,13 +57,18 @@ static int ps3bus_attach(device_t); static int ps3bus_print_child(device_t dev, device_t child); static int ps3bus_read_ivar(device_t bus, device_t child, int which, uintptr_t *result); +static struct rman *ps3bus_get_rman(device_t bus, int type, u_int flags); static struct resource *ps3bus_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 int ps3bus_activate_resource(device_t bus, device_t child, int type, - int rid, struct resource *res); +static int ps3bus_map_resource(device_t bus, device_t child, int type, + struct resource *r, struct resource_map_request *argsp, + struct resource_map *map); +static int ps3bus_unmap_resource(device_t bus, device_t child, int type, + struct resource *r, struct resource_map *map); static bus_dma_tag_t ps3bus_get_dma_tag(device_t dev, device_t child); -static int ps3_iommu_map(device_t dev, bus_dma_segment_t *segs, int *nsegs, bus_addr_t min, bus_addr_t max, bus_size_t alignment, +static int ps3_iommu_map(device_t dev, bus_dma_segment_t *segs, int *nsegs, + bus_addr_t min, bus_addr_t max, bus_size_t alignment, bus_addr_t boundary, void *cookie); static int ps3_iommu_unmap(device_t dev, bus_dma_segment_t *segs, int nsegs, void *cookie); @@ -109,8 +114,14 @@ static device_method_t ps3bus_methods[] = { DEVMETHOD(bus_get_dma_tag, ps3bus_get_dma_tag), DEVMETHOD(bus_print_child, ps3bus_print_child), DEVMETHOD(bus_read_ivar, ps3bus_read_ivar), + DEVMETHOD(bus_get_rman, ps3bus_get_rman), DEVMETHOD(bus_alloc_resource, ps3bus_alloc_resource), - DEVMETHOD(bus_activate_resource, ps3bus_activate_resource), + DEVMETHOD(bus_adjust_resource, bus_generic_rman_adjust_resource), + DEVMETHOD(bus_activate_resource, bus_generic_rman_activate_resource), + DEVMETHOD(bus_deactivate_resource, bus_generic_rman_deactivate_resource), + DEVMETHOD(bus_map_resource, ps3bus_map_resource), + DEVMETHOD(bus_unmap_resource, ps3bus_unmap_resource), + DEVMETHOD(bus_release_resource, bus_generic_rman_release_resource), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), @@ -519,22 +530,31 @@ ps3bus_read_ivar(device_t bus, device_t child, int which, uintptr_t *result) return (0); } +static struct rman * +ps3bus_get_rman(device_t bus, int type, u_int flags) +{ + struct ps3bus_softc *sc; + + sc = device_get_softc(bus); + switch (type) { + case SYS_RES_MEMORY: + return (&sc->sc_mem_rman); + case SYS_RES_IRQ: + return (&sc->sc_intr_rman); + default: + return (NULL); + } +} + static struct resource * ps3bus_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 ps3bus_devinfo *dinfo; - struct ps3bus_softc *sc; - int needactivate; - struct resource *rv; - struct rman *rm; rman_res_t adjstart, adjend, adjcount; struct resource_list_entry *rle; - sc = device_get_softc(bus); dinfo = device_get_ivars(child); - needactivate = flags & RF_ACTIVE; - flags &= ~RF_ACTIVE; switch (type) { case SYS_RES_MEMORY: @@ -561,13 +581,10 @@ ps3bus_alloc_resource(device_t bus, device_t child, int type, int *rid, adjend = end; adjcount = adjend - adjstart; - - rm = &sc->sc_mem_rman; break; case SYS_RES_IRQ: rle = resource_list_find(&dinfo->resources, SYS_RES_IRQ, *rid); - rm = &sc->sc_intr_rman; adjstart = rle->start; adjcount = ulmax(count, rle->count); adjend = ulmax(rle->end, rle->start + adjcount - 1); @@ -578,58 +595,59 @@ ps3bus_alloc_resource(device_t bus, device_t child, int type, int *rid, return (NULL); } - rv = rman_reserve_resource(rm, adjstart, adjend, adjcount, flags, - child); - if (rv == NULL) { - device_printf(bus, - "failed to reserve resource %#lx - %#lx (%#lx)" - " for %s\n", adjstart, adjend, adjcount, - 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); - } - } - - return (rv); + return (bus_generic_rman_alloc_resource(bus, child, type, rid, adjstart, + adjend, adjcount, flags)); } static int -ps3bus_activate_resource(device_t bus, device_t child, int type, int rid, - struct resource *res) +ps3bus_map_resource(device_t bus, device_t child, int type, struct resource *r, + struct resource_map_request *argsp, struct resource_map *map) { - void *p; + struct resource_map_request args; + rman_res_t length, start; + int error; - if (type == SYS_RES_IRQ) - return (bus_activate_resource(bus, type, rid, res)); + /* Resources must be active to be mapped. */ + if (!(rman_get_flags(r) & RF_ACTIVE)) + return (ENXIO); - if (type == SYS_RES_MEMORY) { - vm_offset_t start; + /* Mappings are only supported on memory resources. */ + switch (type) { + case SYS_RES_MEMORY: + break; + default: + return (EINVAL); + } - start = (vm_offset_t) rman_get_start(res); + resource_init_map_request(&args); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); - if (bootverbose) - printf("ps3 mapdev: start %zx, len %ld\n", start, - rman_get_size(res)); + if (bootverbose) + printf("ps3 mapdev: start %jx, len %jd\n", start, length); - p = pmap_mapdev(start, (vm_size_t) rman_get_size(res)); - if (p == NULL) - return (ENOMEM); - rman_set_virtual(res, p); - rman_set_bustag(res, &bs_be_tag); - rman_set_bushandle(res, (rman_res_t)p); - } + map->r_vaddr = pmap_mapdev_attr(start, length, args.memattr); + if (map->r_vaddr == NULL) + return (ENOMEM); + map->r_bustag = &bs_be_tag; + map->r_bushandle = (vm_offset_t)map->r_vaddr; + map->r_size = length; + return (0); +} + +static int +ps3bus_unmap_resource(device_t bus, device_t child, int type, + struct resource *r, struct resource_map *map) +{ - return (rman_activate_resource(res)); + switch (type) { + case SYS_RES_MEMORY: + pmap_unmapdev(map->r_vaddr, map->r_size); + return (0); + default: + return (EINVAL); + } } static bus_dma_tag_t