From nobody Wed Dec 11 23:14:53 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 4Y7rzL1gbgz5gcl5; Wed, 11 Dec 2024 23:14: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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y7rzK6bpqz44nl; Wed, 11 Dec 2024 23:14:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733958893; 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=sBasXUdqZriQZzPoyH3ZyCgYNkBEL+mqKwMV9gN8qnM=; b=TvVtwDzuahFxLEmYXihsPA+GiJbX3Wosnz+xpVSB1v/544i9EB9B9w3xkauqrmRhW57nDG fX+ER8kfPrKqbXeiyZqH6Md5500otCq/gjSysl1ED82trYa/1C4EqRjx5valE/q3nGD5ra nqyHS4/a/UVj+ZKhM8MSFEjN2OQDMCLjsLStiXgxAY0lh2Uj5/wKdIA+zDJg/Jc82xXHTO /UoducYOjTC/eGcy4DGKrt2Pi0zT3Sl55SRETuHR4dpk2ztFEAtG8CiBgPMYetKvmiWaQf IMQ/3lT7lJcjrjMLZpz5rJt+B6RamXZ+ZCex0Lld+6R86PqnquWW6cTL4qdIzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733958893; 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=sBasXUdqZriQZzPoyH3ZyCgYNkBEL+mqKwMV9gN8qnM=; b=q8F648qRB4l7UlHQCxS8KYCSRP5Vuj/OFoXciKLUL4/I/q7HSZHKNkv9BYYgB922BC9zUH rDwiE5x04cj25OFK9242dZB3T+CSoq9MO9RSZ8+nkglXoSnlZulb07v/dOoaYzg8FsJAv8 qNFtbyFlpS0ltNowY8XjWXs4CuegYv/dzoovD4fccas/k9xD7kNeep4ahOL1uxUaVd6Wn0 xH45Ue1vCU1SpohmgYIKM/K0WEce/v0PFez4XM+wr1RM2/TDejXrCOhpzteH0J7ri6dmTh LoHQpZM1J4TBHM+2Ba6ivjtwVZsP6q+axiaOp1+1pRRT3ssQpy9yc6tXG6Na2Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733958893; a=rsa-sha256; cv=none; b=nCamKWpzOLJvhm+yLyj3yL6ktccuglwkjfxk8dZTIgH35FajkNtiK4WQtRDG4sZZsDIXaB Y94DOfwYlPGoPAPqmH9aWCE12UxVyoBszk2FK9SK/DMVvjOucz+b8i6CRYsdeYqxbydfzb GEknfw62AYFyfqrTGqUJFpYJtTBKeXRDoinFoJTvMyKF5od9yMtXmpdMt3XheKWHAn011Q F05dthgM9b7KhKZIk3UGBTwQfsz5vXsiN2CRBwksrou82h7k9ssrmSKrhkRgZVmnildRsE zs13SiKWOyt708lgAr1IjMlIVcntIHckHnc59Th2Kf3stRDfuRoTtx2UZltw+A== 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 4Y7rzK6ByjzS9t; Wed, 11 Dec 2024 23:14:53 +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 4BBNErHd063675; Wed, 11 Dec 2024 23:14:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BBNErTt063672; Wed, 11 Dec 2024 23:14:53 GMT (envelope-from git) Date: Wed, 11 Dec 2024 23:14:53 GMT Message-Id: <202412112314.4BBNErTt063672@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 90fb07edbd7a - main - intr/x86: add ioapic_drv_t to reduce number of casts in IO-APIC implementation 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 90fb07edbd7adb653bd8dc1aac09a63b7ff76f89 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=90fb07edbd7adb653bd8dc1aac09a63b7ff76f89 commit 90fb07edbd7adb653bd8dc1aac09a63b7ff76f89 Author: Elliott Mitchell AuthorDate: 2024-10-01 19:56:25 +0000 Commit: Warner Losh CommitDate: 2024-12-11 23:14:30 +0000 intr/x86: add ioapic_drv_t to reduce number of casts in IO-APIC implementation void * is handy when you truly do not care about the type. Yet there is so much casting back and forth in the IO-APIC code as to be hazardous. Achieve better static checking by the compiler using a typedef. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1457 --- sys/x86/include/apicvar.h | 24 +++++++++++++----------- sys/x86/x86/io_apic.c | 42 +++++++++++------------------------------- sys/x86/x86/mptable.c | 4 ++-- 3 files changed, 26 insertions(+), 44 deletions(-) diff --git a/sys/x86/include/apicvar.h b/sys/x86/include/apicvar.h index 61c726f150df..fc9bb0123539 100644 --- a/sys/x86/include/apicvar.h +++ b/sys/x86/include/apicvar.h @@ -196,19 +196,21 @@ extern int *apic_cpuids; /* Allow to replace the lapic_ipi_vectored implementation. */ extern void (*ipi_vectored)(u_int, int); +typedef struct ioapic *ioapic_drv_t; + void apic_register_enumerator(struct apic_enumerator *enumerator); -void *ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase); -int ioapic_disable_pin(void *cookie, u_int pin); -int ioapic_get_vector(void *cookie, u_int pin); -void ioapic_register(void *cookie); -int ioapic_remap_vector(void *cookie, u_int pin, int vector); -int ioapic_set_bus(void *cookie, u_int pin, int bus_type); -int ioapic_set_extint(void *cookie, u_int pin); -int ioapic_set_nmi(void *cookie, u_int pin); -int ioapic_set_polarity(void *cookie, u_int pin, enum intr_polarity pol); -int ioapic_set_triggermode(void *cookie, u_int pin, +ioapic_drv_t ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase); +int ioapic_disable_pin(ioapic_drv_t cookie, u_int pin); +int ioapic_get_vector(ioapic_drv_t cookie, u_int pin); +void ioapic_register(ioapic_drv_t cookie); +int ioapic_remap_vector(ioapic_drv_t cookie, u_int pin, int vector); +int ioapic_set_bus(ioapic_drv_t cookie, u_int pin, int bus_type); +int ioapic_set_extint(ioapic_drv_t cookie, u_int pin); +int ioapic_set_nmi(ioapic_drv_t cookie, u_int pin); +int ioapic_set_polarity(ioapic_drv_t cookie, u_int pin, enum intr_polarity pol); +int ioapic_set_triggermode(ioapic_drv_t cookie, u_int pin, enum intr_trigger trigger); -int ioapic_set_smi(void *cookie, u_int pin); +int ioapic_set_smi(ioapic_drv_t cookie, u_int pin); void lapic_create(u_int apic_id, int boot_cpu); void lapic_init(vm_paddr_t addr); diff --git a/sys/x86/x86/io_apic.c b/sys/x86/x86/io_apic.c index 36c7cba77a35..d0f47f82011a 100644 --- a/sys/x86/x86/io_apic.c +++ b/sys/x86/x86/io_apic.c @@ -606,7 +606,7 @@ ioapic_resume(struct pic *pic, bool suspend_cancelled) /* * Create a plain I/O APIC object. */ -void * +ioapic_drv_t ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase) { struct ioapic *io; @@ -727,22 +727,18 @@ ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase) } int -ioapic_get_vector(void *cookie, u_int pin) +ioapic_get_vector(ioapic_drv_t io, u_int pin) { - struct ioapic *io; - io = (struct ioapic *)cookie; if (pin >= io->io_numintr) return (-1); return (io->io_pins[pin].io_irq); } int -ioapic_disable_pin(void *cookie, u_int pin) +ioapic_disable_pin(ioapic_drv_t io, u_int pin) { - struct ioapic *io; - io = (struct ioapic *)cookie; if (pin >= io->io_numintr) return (EINVAL); if (io->io_pins[pin].io_irq == IRQ_DISABLED) @@ -754,11 +750,9 @@ ioapic_disable_pin(void *cookie, u_int pin) } int -ioapic_remap_vector(void *cookie, u_int pin, int vector) +ioapic_remap_vector(ioapic_drv_t io, u_int pin, int vector) { - struct ioapic *io; - io = (struct ioapic *)cookie; if (pin >= io->io_numintr || vector < 0) return (EINVAL); if (io->io_pins[pin].io_irq < 0) @@ -771,13 +765,11 @@ ioapic_remap_vector(void *cookie, u_int pin, int vector) } int -ioapic_set_bus(void *cookie, u_int pin, int bus_type) +ioapic_set_bus(ioapic_drv_t io, u_int pin, int bus_type) { - struct ioapic *io; if (bus_type < 0 || bus_type > APIC_BUS_MAX) return (EINVAL); - io = (struct ioapic *)cookie; if (pin >= io->io_numintr) return (EINVAL); if (io->io_pins[pin].io_irq < 0) @@ -792,11 +784,9 @@ ioapic_set_bus(void *cookie, u_int pin, int bus_type) } int -ioapic_set_nmi(void *cookie, u_int pin) +ioapic_set_nmi(ioapic_drv_t io, u_int pin) { - struct ioapic *io; - io = (struct ioapic *)cookie; if (pin >= io->io_numintr) return (EINVAL); if (io->io_pins[pin].io_irq == IRQ_NMI) @@ -815,11 +805,9 @@ ioapic_set_nmi(void *cookie, u_int pin) } int -ioapic_set_smi(void *cookie, u_int pin) +ioapic_set_smi(ioapic_drv_t io, u_int pin) { - struct ioapic *io; - io = (struct ioapic *)cookie; if (pin >= io->io_numintr) return (EINVAL); if (io->io_pins[pin].io_irq == IRQ_SMI) @@ -838,11 +826,9 @@ ioapic_set_smi(void *cookie, u_int pin) } int -ioapic_set_extint(void *cookie, u_int pin) +ioapic_set_extint(ioapic_drv_t io, u_int pin) { - struct ioapic *io; - io = (struct ioapic *)cookie; if (pin >= io->io_numintr) return (EINVAL); if (io->io_pins[pin].io_irq == IRQ_EXTINT) @@ -864,12 +850,10 @@ ioapic_set_extint(void *cookie, u_int pin) } int -ioapic_set_polarity(void *cookie, u_int pin, enum intr_polarity pol) +ioapic_set_polarity(ioapic_drv_t io, u_int pin, enum intr_polarity pol) { - struct ioapic *io; int activehi; - io = (struct ioapic *)cookie; if (pin >= io->io_numintr || pol == INTR_POLARITY_CONFORM) return (EINVAL); if (io->io_pins[pin].io_irq < 0) @@ -885,12 +869,10 @@ ioapic_set_polarity(void *cookie, u_int pin, enum intr_polarity pol) } int -ioapic_set_triggermode(void *cookie, u_int pin, enum intr_trigger trigger) +ioapic_set_triggermode(ioapic_drv_t io, u_int pin, enum intr_trigger trigger) { - struct ioapic *io; int edgetrigger; - io = (struct ioapic *)cookie; if (pin >= io->io_numintr || trigger == INTR_TRIGGER_CONFORM) return (EINVAL); if (io->io_pins[pin].io_irq < 0) @@ -909,15 +891,13 @@ ioapic_set_triggermode(void *cookie, u_int pin, enum intr_trigger trigger) * Register a complete I/O APIC object with the interrupt subsystem. */ void -ioapic_register(void *cookie) +ioapic_register(ioapic_drv_t io) { struct ioapic_intsrc *pin; - struct ioapic *io; volatile ioapic_t *apic; uint32_t flags; int i; - io = (struct ioapic *)cookie; apic = io->io_addr; mtx_lock_spin(&icu_lock); flags = ioapic_read(apic, IOAPIC_VER) & IOART_VER_VERSION; diff --git a/sys/x86/x86/mptable.c b/sys/x86/x86/mptable.c index 03b4d4362baa..4f078fd05ec6 100644 --- a/sys/x86/x86/mptable.c +++ b/sys/x86/x86/mptable.c @@ -157,7 +157,7 @@ struct pci_route_interrupt_args { static mpfps_t mpfps; static mpcth_t mpct; static ext_entry_ptr mpet; -static void *ioapics[IOAPIC_MAX_ID + 1]; +static ioapic_drv_t ioapics[IOAPIC_MAX_ID + 1]; static bus_datum *busses; static int mptable_nioapics, mptable_nbusses, mptable_maxbusid; static int pci0 = -1; @@ -760,7 +760,7 @@ intentry_trigger(int_entry_ptr intr) static void mptable_parse_io_int(int_entry_ptr intr) { - void *ioapic; + ioapic_drv_t ioapic; u_int pin, apic_id; apic_id = intr->dst_apic_id;