From nobody Mon Mar 20 20:36:55 2023 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 4PgRNm1Vdcz40CjG; Mon, 20 Mar 2023 20:36:56 +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 4PgRNl6m4Wz3h6W; Mon, 20 Mar 2023 20:36:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679344616; 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=4Fvp6KNfIjXCvCe4Ro9fSf6YSayGtfBUNI/h4buSqg4=; b=GGcOHJykj/DgTB1ANP/dNWzu0wXFbhhbwb7JRxb6ASa2Ea0TrGuCyAk1MY07wQ8Z5ogR0B MdxEZaKTaLjTHTfjNFQf/39D2biaXSNYrUOIkdXsbEJinkagvrSY1Gt95xgkZ1EO9f7xv6 rL5C8pZN9QdAESe+3jfepwmOTD+lJ+vQd1s+a8x/JUYojHYqdUak3Ze1kCnGIwrOGQfGaS M0RPvuocSDtGnim9xzEuklXUYZJYQoAVoRLglTKFQnfz7fW1rjmawabjMYs/cRFcKYWBc3 FU8gWK7uo2csNqjtrZcLg+JkmHnE5aMCS6nxwZufTxU8dRxX6FaHyTRg0aZ6Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679344616; 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=4Fvp6KNfIjXCvCe4Ro9fSf6YSayGtfBUNI/h4buSqg4=; b=qG/5ScwpARIds/07/kGRX2yUfXnBuTHd1+ojvcsBeFdTscyHAsOVRbn6CAUxYoo/Y/Emxy /RTA+HakmFXvGFdY5L+IKywjOIjoE2fR9ogoFnSei3R0L0khgUuJG20zwfGAe2BlYIrX0o hlbMx6g0JRlAPKUCg5pzBk+ZeZnubJTOLrlFnse/n3CWXgxCrrnXnDT0/7jQy3nc0HBe1M 4PQwkYoADw/vJvAEtHWX5TdLmg0jA5yF5/uEsXXbLSDKcepUwPJd8XnH38z+NzZ0xza3+M coen4YWdCciKr5SHqpSIUuQ0ppfyrrGgufl2a1reoSu6HMUvkQ6KeP9UsNDfNQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679344616; a=rsa-sha256; cv=none; b=dqlI+/Gs/Oa5k5fQSdeMy30V+jv4AP9qDWNcs+NHg05gpOR1k3ZHgBEShzj2b4SgMJRt4t HYv3qeUC35V9aQ+o3BwvPB7WNFD9DCcYOrUGNRTymUyL/oPW80Yo78EFS514l3aJnzrs5b hKD3NVqOpkuUTYg4YAFFElF6wm2Rnaif18Ox7idNiQG6Eu2I6G0MfAeCYcermrLqS/ik0+ bABpWTwjOA6M5YGUFLnE53KSZ9zXgPvG0h/73ct1cL6nE3E7t2KrsZfgDMLv38qOjNSR/Z JcFYbDmZLt8rF+zCgtOkRMoEGVo5pKy9YGTIIQVUChVwtTFaJiUXhJCPxWRaCQ== 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 4PgRNl5fp5zkdy; Mon, 20 Mar 2023 20:36:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32KKatDX066279; Mon, 20 Mar 2023 20:36:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32KKatKu066278; Mon, 20 Mar 2023 20:36:55 GMT (envelope-from git) Date: Mon, 20 Mar 2023 20:36:55 GMT Message-Id: <202303202036.32KKatKu066278@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 99bd5c1fe322 - main - x86: nexus code tidy-up 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 99bd5c1fe32272ce6e8d9b2d575b42dd94593b25 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=99bd5c1fe32272ce6e8d9b2d575b42dd94593b25 commit 99bd5c1fe32272ce6e8d9b2d575b42dd94593b25 Author: Mitchell Horne AuthorDate: 2023-02-10 14:52:38 +0000 Commit: Mitchell Horne CommitDate: 2023-03-20 20:35:47 +0000 x86: nexus code tidy-up Make a pass at the various nexus implementations, fixing some very minor style issues, obsolete comments, etc. The method declaration section has become unwieldy in many respects. Attempt to tame it by: - Using generated method typedefs - Grouping methods roughly by category, and then alphabetically. Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D38495 --- sys/x86/x86/nexus.c | 165 ++++++++++++++++++++++++---------------------------- 1 file changed, 76 insertions(+), 89 deletions(-) diff --git a/sys/x86/x86/nexus.c b/sys/x86/x86/nexus.c index 5bb53c22de1c..d02d081de1e8 100644 --- a/sys/x86/x86/nexus.c +++ b/sys/x86/x86/nexus.c @@ -52,16 +52,13 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include -#include -#include #include -#include -#include #include #include #include @@ -69,10 +66,13 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include +#include #include #include -#include #include +#include #ifdef DEV_APIC #include "pcib_if.h" @@ -82,7 +82,6 @@ __FBSDID("$FreeBSD$"); #include #include #endif -#include #define ELF_KERN_STR ("elf"__XSTRING(__ELF_WORD_SIZE)" kernel") @@ -92,58 +91,44 @@ static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device"); struct rman irq_rman, drq_rman, port_rman, mem_rman; -static int nexus_probe(device_t); -static int nexus_attach(device_t); -static int nexus_print_all_resources(device_t dev); -static int nexus_print_child(device_t, device_t); -static device_t nexus_add_child(device_t bus, u_int order, const char *name, - int unit); -static struct resource *nexus_alloc_resource(device_t, device_t, int, int *, - rman_res_t, rman_res_t, rman_res_t, - u_int); -static int nexus_adjust_resource(device_t, device_t, int, struct resource *, - rman_res_t, rman_res_t); +static int nexus_print_all_resources(device_t dev); + +static device_probe_t nexus_probe; +static device_attach_t nexus_attach; + +static bus_add_child_t nexus_add_child; +static bus_print_child_t nexus_print_child; + +static bus_activate_resource_t nexus_activate_resource; +static bus_adjust_resource_t nexus_adjust_resource; +static bus_alloc_resource_t nexus_alloc_resource; +static bus_deactivate_resource_t nexus_deactivate_resource; +static bus_delete_resource_t nexus_delete_resource; +static bus_get_resource_t nexus_get_resource; +static bus_get_resource_list_t nexus_get_reslist; +static bus_map_resource_t nexus_map_resource; +static bus_release_resource_t nexus_release_resource; +static bus_set_resource_t nexus_set_resource; +static bus_unmap_resource_t nexus_unmap_resource; + #ifdef SMP -static int nexus_bind_intr(device_t, device_t, struct resource *, int); +static bus_bind_intr_t nexus_bind_intr; #endif -static int nexus_config_intr(device_t, int, enum intr_trigger, - enum intr_polarity); -static int nexus_describe_intr(device_t dev, device_t child, - struct resource *irq, void *cookie, - const char *descr); -static int nexus_activate_resource(device_t, device_t, int, int, - struct resource *); -static int nexus_deactivate_resource(device_t, device_t, int, int, - struct resource *); -static int nexus_map_resource(device_t bus, device_t child, int type, - struct resource *r, - struct resource_map_request *argsp, - struct resource_map *map); -static int nexus_unmap_resource(device_t bus, device_t child, int type, - struct resource *r, struct resource_map *map); -static int nexus_release_resource(device_t, device_t, int, int, - struct resource *); -static int nexus_setup_intr(device_t, device_t, struct resource *, int flags, - driver_filter_t filter, void (*)(void *), void *, - void **); -static int nexus_teardown_intr(device_t, device_t, struct resource *, - void *); -static int nexus_suspend_intr(device_t, device_t, struct resource *); -static int nexus_resume_intr(device_t, device_t, struct resource *); -static struct resource_list *nexus_get_reslist(device_t dev, device_t child); -static int nexus_set_resource(device_t, device_t, int, int, - rman_res_t, rman_res_t); -static int nexus_get_resource(device_t, device_t, int, int, - rman_res_t *, rman_res_t *); -static void nexus_delete_resource(device_t, device_t, int, int); -static int nexus_get_cpus(device_t, device_t, enum cpu_sets, size_t, - cpuset_t *); +static bus_config_intr_t nexus_config_intr; +static bus_describe_intr_t nexus_describe_intr; +static bus_resume_intr_t nexus_resume_intr; +static bus_setup_intr_t nexus_setup_intr; +static bus_suspend_intr_t nexus_suspend_intr; +static bus_teardown_intr_t nexus_teardown_intr; + +static bus_get_cpus_t nexus_get_cpus; + #if defined(DEV_APIC) && defined(DEV_PCI) -static int nexus_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs); -static int nexus_release_msi(device_t pcib, device_t dev, int count, int *irqs); -static int nexus_alloc_msix(device_t pcib, device_t dev, int *irq); -static int nexus_release_msix(device_t pcib, device_t dev, int irq); -static int nexus_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data); +static pcib_alloc_msi_t nexus_alloc_msi; +static pcib_release_msi_t nexus_release_msi; +static pcib_alloc_msix_t nexus_alloc_msix; +static pcib_release_msix_t nexus_release_msix; +static pcib_map_msi_t nexus_map_msi; #endif static device_method_t nexus_methods[] = { @@ -158,26 +143,26 @@ static device_method_t nexus_methods[] = { /* Bus interface */ DEVMETHOD(bus_print_child, nexus_print_child), DEVMETHOD(bus_add_child, nexus_add_child), - DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), - DEVMETHOD(bus_adjust_resource, nexus_adjust_resource), - DEVMETHOD(bus_release_resource, nexus_release_resource), DEVMETHOD(bus_activate_resource, nexus_activate_resource), + DEVMETHOD(bus_adjust_resource, nexus_adjust_resource), + DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource), + DEVMETHOD(bus_get_resource, nexus_get_resource), + DEVMETHOD(bus_get_resource_list, nexus_get_reslist), + DEVMETHOD(bus_delete_resource, nexus_delete_resource), DEVMETHOD(bus_map_resource, nexus_map_resource), + DEVMETHOD(bus_release_resource, nexus_release_resource), + DEVMETHOD(bus_set_resource, nexus_set_resource), DEVMETHOD(bus_unmap_resource, nexus_unmap_resource), - DEVMETHOD(bus_setup_intr, nexus_setup_intr), - DEVMETHOD(bus_teardown_intr, nexus_teardown_intr), - DEVMETHOD(bus_suspend_intr, nexus_suspend_intr), - DEVMETHOD(bus_resume_intr, nexus_resume_intr), #ifdef SMP DEVMETHOD(bus_bind_intr, nexus_bind_intr), #endif DEVMETHOD(bus_config_intr, nexus_config_intr), DEVMETHOD(bus_describe_intr, nexus_describe_intr), - DEVMETHOD(bus_get_resource_list, nexus_get_reslist), - DEVMETHOD(bus_set_resource, nexus_set_resource), - DEVMETHOD(bus_get_resource, nexus_get_resource), - DEVMETHOD(bus_delete_resource, nexus_delete_resource), + DEVMETHOD(bus_resume_intr, nexus_resume_intr), + DEVMETHOD(bus_setup_intr, nexus_setup_intr), + DEVMETHOD(bus_suspend_intr, nexus_suspend_intr), + DEVMETHOD(bus_teardown_intr, nexus_teardown_intr), DEVMETHOD(bus_get_cpus, nexus_get_cpus), /* pcib interface */ @@ -188,7 +173,7 @@ static device_method_t nexus_methods[] = { DEVMETHOD(pcib_release_msix, nexus_release_msix), DEVMETHOD(pcib_map_msi, nexus_map_msi), #endif - { 0, 0 } + DEVMETHOD_END }; DEFINE_CLASS_0(nexus, nexus_driver, nexus_methods, 1); @@ -294,7 +279,7 @@ nexus_attach(device_t dev) if (BUS_ADD_CHILD(dev, 10, "legacy", 0) == NULL) panic("legacy: could not attach"); bus_generic_attach(dev); - return 0; + return (0); } static int @@ -311,7 +296,7 @@ nexus_print_all_resources(device_t dev) retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#jx"); retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%jd"); - return retval; + return (retval); } static int @@ -336,7 +321,7 @@ nexus_add_child(device_t bus, u_int order, const char *name, int unit) ndev = malloc(sizeof(struct nexus_device), M_NEXUSDEV, M_NOWAIT|M_ZERO); if (!ndev) - return(0); + return (0); resource_list_init(&ndev->nx_resources); child = device_add_child_ordered(bus, order, name, unit); @@ -344,7 +329,7 @@ nexus_add_child(device_t bus, u_int order, const char *name, int unit) /* should we free this in nexus_child_detached? */ device_set_ivars(child, ndev); - return(child); + return (child); } static struct rman * @@ -367,7 +352,6 @@ nexus_rman(int type) /* * Allocate a resource on behalf of child. NB: child is usually going to be a * child of one of our descendants, not a direct child of nexus0. - * (Exceptions include npx.) */ static struct resource * nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, @@ -388,10 +372,10 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, */ if (RMAN_IS_DEFAULT_RANGE(start, end) && (count == 1)) { if (device_get_parent(child) != bus || ndev == NULL) - return(NULL); + return (NULL); rle = resource_list_find(&ndev->nx_resources, type, *rid); if (rle == NULL) - return(NULL); + return (NULL); start = rle->start; end = rle->end; count = rle->count; @@ -404,17 +388,17 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, rv = rman_reserve_resource(rm, start, end, count, flags, child); if (rv == NULL) - return 0; + return (0); rman_set_rid(rv, *rid); if (needactivate) { if (bus_activate_resource(child, type, *rid, rv)) { rman_release_resource(rv); - return 0; + return (0); } } - return rv; + return (rv); } static int @@ -556,11 +540,12 @@ static int nexus_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { + int error; if (rman_get_flags(r) & RF_ACTIVE) { - int error = bus_deactivate_resource(child, type, rid, r); - if (error) - return error; + error = bus_deactivate_resource(child, type, rid, r); + if (error != 0) + return (error); } return (rman_release_resource(r)); } @@ -590,7 +575,7 @@ nexus_setup_intr(device_t bus, device_t child, struct resource *irq, * We depend here on rman_activate_resource() being idempotent. */ error = rman_activate_resource(irq); - if (error) + if (error != 0) return (error); if (bus_get_domain(child, &domain) != 0) domain = 0; @@ -666,7 +651,7 @@ nexus_set_resource(device_t dev, device_t child, int type, int rid, /* XXX this should return a success/failure indicator */ resource_list_add(rl, type, rid, start, start + count - 1, count); - return(0); + return (0); } static int @@ -679,12 +664,12 @@ nexus_get_resource(device_t dev, device_t child, int type, int rid, rle = resource_list_find(rl, type, rid); if (!rle) - return(ENOENT); + return (ENOENT); if (startp) *startp = rle->start; if (countp) *countp = rle->count; - return(0); + return (0); } static void @@ -794,7 +779,7 @@ ram_attach(device_t dev) /* Retrieve the system memory map from the loader. */ kmdp = preload_search_by_type("elf kernel"); if (kmdp == NULL) - kmdp = preload_search_by_type(ELF_KERN_STR); + kmdp = preload_search_by_type(ELF_KERN_STR); smapbase = (struct bios_smap *)preload_search_info(kmdp, MODINFO_METADATA | MODINFOMD_SMAP); if (smapbase != NULL) { @@ -857,7 +842,8 @@ static device_method_t ram_methods[] = { DEVMETHOD(device_identify, ram_identify), DEVMETHOD(device_probe, ram_probe), DEVMETHOD(device_attach, ram_attach), - { 0, 0 } + + DEVMETHOD_END }; static driver_t ram_driver = { @@ -887,13 +873,13 @@ sysresource_probe(device_t dev) if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, sysresource_ids)) <= 0) { device_quiet(dev); } - return(result); + return (result); } static int sysresource_attach(device_t dev) { - return(0); + return (0); } static device_method_t sysresource_methods[] = { @@ -904,7 +890,8 @@ static device_method_t sysresource_methods[] = { DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, bus_generic_resume), - { 0, 0 } + + DEVMETHOD_END }; static driver_t sysresource_driver = {