From nobody Mon Nov 09 18:36:57 2026 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 4jNdmT2sHQz70H3m for ; Mon, 09 Nov 2026 18:36: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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jNdmT0kgbz4HWb for ; Mon, 09 Nov 2026 18:36:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794249417; 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=wNt3Kn4adTNDvIOpKbTpqX7T+9NYRY0Bmuq3qbGTOn8=; b=nDERwPuGRAc/Maqzd+A5+FKHmASm0XJJPTQcgSPSBzV9EchGDfXGuHiCILdYYMslcnjMgP hXuCRkSkBFu1pcUEy/QunjftB/hcwMcBC7zRZOq59n3zM+Y64SOLC0zR3xmhTIlTZJ6VFi l84DJ3+U7aRmm184hxFUt7evnG1chbzExYceyMtzycqzC4gi34WOLMmlGj6zxk1jODXEEv U8EWLVNRdLT+ErG2Y09W2osK63K5W76MnuG+Q+YQEGDWS0HyBs3H/9qKOCl/r1lzaHyT02 LnClLvMcr32+4FJarKujo8y7szh5ASkv5OmcXYrBa+uHIUqDE+Zr8mKOO6lSsQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794249417; b=smQ8NPuafU4UbDg+Ue9LoDZt52o03HLlNPAgYatLmwHIDDKT4Y5D7al3Fw4fKKclehntpH TUHKwu+nwNiRZW7zvzJqvaxaTc66SqTJyzjvoeEwqLdR1OiMLGTblPeWE2yO2SvpBeAmS+ KLwcg3chQb3kjSPA949ZuhuY8e8UL4WQ9c28LynIwW8eT7YTLoygQ/wSL6IDYWQBmJ0mP3 VYUbNgQtuarIgXkrZgSk6YZqAraZ24fBpuB6toI95V6NQp2U3+V1w5MGDhC4ZwDhHrkOmw knuHiSHdlU7RkCyxDZhizOtXFCDHqhKvvUJNvYIrnamgi1rLbq9U7aL7uvGpZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794249417; 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=wNt3Kn4adTNDvIOpKbTpqX7T+9NYRY0Bmuq3qbGTOn8=; b=Cz41jhVzAqKCgGYs3K7XO6PFZ7Y1ELa0z7WLxWH2mYCvQrX4PJLFW4mNNISeHwbrzzGscv gmruJ0HJMqCOhBujX/ImXthRWWt0CqYaCAbpj4oaYJTOPYOde3NzgwfsN1ei98SizSMVsB t4jfnzwuCErb29VGxJm5zgJVs175ES9Pvow4BbL2z9q0nWVPY82dT8g6TSpGI97UhhfUFi faklpAu55tf7FmExP0+oNDurOY/+NbSIWPusshU3lydtEcER2K080MVdg8iI4X3h+tCcpu hPCCcECuSLGbH9Mt9sUxXmQBie94e33+oaXFeKt5/rI00dDIdH2bQNm311jN3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jNdmT0MtQzssc for ; Mon, 09 Nov 2026 18:36:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id b84e by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 09 Nov 2026 18:36:57 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Abdelkader Boudih Subject: git: c714cde179a4 - main - asmc: split the sysctl layer into asmcsysctl.c List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: seuros X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c714cde179a412b95535d2377fcc8dd4e192755e Auto-Submitted: auto-generated Date: Mon, 09 Nov 2026 18:36:57 +0000 Message-Id: <6af212c9.b84e.2e336a14@gitrepo.freebsd.org> The branch main has been updated by seuros: URL: https://cgit.FreeBSD.org/src/commit/?id=c714cde179a412b95535d2377fcc8dd4e192755e commit c714cde179a412b95535d2377fcc8dd4e192755e Author: Abdelkader Boudih AuthorDate: 2026-11-09 18:35:30 +0000 Commit: Abdelkader Boudih CommitDate: 2026-11-09 18:35:30 +0000 asmc: split the sysctl layer into asmcsysctl.c Moved the dev.asmc.N tree out of asmc.c No functional change MFC After: 1 Week Approved-by: ngie (co-mentor) Reviewed by: ngie Differential Revision: https://reviews.freebsd.org/D61300 --- sys/conf/files.amd64 | 1 + sys/dev/asmc/asmc.c | 1057 +--------------------------------------- sys/dev/asmc/asmc_sysctl.c | 1147 ++++++++++++++++++++++++++++++++++++++++++++ sys/dev/asmc/asmc_sysctl.h | 25 + sys/dev/asmc/asmcvar.h | 57 +-- sys/modules/asmc/Makefile | 2 +- 6 files changed, 1183 insertions(+), 1106 deletions(-) diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 index 887c619abc51..16a9b13d3585 100644 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -119,6 +119,7 @@ dev/apple_bce/apple_bce_vhci.c optional apple_bce pci usb dev/asmc/asmc.c optional asmc isa dev/asmc/asmc_debug.c optional asmc isa asmc_debug dev/asmc/asmc_pio.c optional asmc isa +dev/asmc/asmc_sysctl.c optional asmc isa dev/asmc/asmcmmio.c optional asmc isa dev/axgbe/if_axgbe_pci.c optional axp dev/axgbe/xgbe-desc.c optional axp diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c index e2872dac1c3d..9db81e32b06d 100644 --- a/sys/dev/asmc/asmc.c +++ b/sys/dev/asmc/asmc.c @@ -38,10 +38,8 @@ #include #include -#include #include #include -#include #include #include #include @@ -61,6 +59,7 @@ #include #include #include +#include #include #include @@ -89,10 +88,6 @@ static int asmc_backlight_get_info(device_t dev, struct backlight_info *info); */ static int asmc_init(device_t dev); static int asmc_fan_count(device_t dev); -static int asmc_fan_getvalue(device_t dev, const char *key, int fan); -static int asmc_fan_setvalue(device_t dev, const char *key, int fan, int speed); -static int asmc_temp_getvalue(device_t dev, const char *key); -static int asmc_sms_read(device_t, const char *key, int16_t *val); static void asmc_sms_calibrate(device_t dev); static int asmc_sms_intrfast(void *arg); static void asmc_sms_printintr(device_t dev, uint8_t); @@ -100,246 +95,11 @@ static void asmc_sms_task(void *arg, int pending); static void asmc_sms_init(device_t dev); static void asmc_detect_capabilities(device_t dev); -/* - * Sysctl handlers. - */ -static int asmc_mb_sysctl_fanid(SYSCTL_HANDLER_ARGS); -static int asmc_mb_sysctl_fanspeed(SYSCTL_HANDLER_ARGS); -static int asmc_mb_sysctl_fanmanual(SYSCTL_HANDLER_ARGS); -static int asmc_temp_sysctl(SYSCTL_HANDLER_ARGS); -static int asmc_mb_sysctl_sms(SYSCTL_HANDLER_ARGS); -static int asmc_mbp_sysctl_light(SYSCTL_HANDLER_ARGS); -static int asmc_mbp_sysctl_light_control(SYSCTL_HANDLER_ARGS); -static int asmc_mbp_sysctl_light_left_10byte(SYSCTL_HANDLER_ARGS); -static int asmc_aupo_sysctl(SYSCTL_HANDLER_ARGS); -static int asmc_sil_sysctl(SYSCTL_HANDLER_ARGS); - -/* System state / board identity sysctls */ -static int asmc_cause_sysctl(SYSCTL_HANDLER_ARGS); -static int asmc_msal_sysctl(SYSCTL_HANDLER_ARGS); -static int asmc_clkt_sysctl(SYSCTL_HANDLER_ARGS); -static int asmc_msps_sysctl(SYSCTL_HANDLER_ARGS); -static int asmc_rplt_sysctl(SYSCTL_HANDLER_ARGS); -static int asmc_rgen_sysctl(SYSCTL_HANDLER_ARGS); /* Voltage/Current/Power/Light sensor support */ -static int asmc_sensor_read(device_t, const char *, int *); -static int asmc_sensor_sysctl(SYSCTL_HANDLER_ARGS); static int asmc_detect_sensors(device_t); static int asmc_key_search(device_t, const char *, unsigned int *); -static const char *asmc_temp_desc(const char *key); - -/* - * SMC temperature key descriptions. - * These are universal across all Intel Apple hardware. - */ -static const struct { - const char *key; - const char *desc; -} asmc_temp_descs[] = { - /* Ambient / airflow */ - { "TA0P", "Ambient" }, - { "TA0S", "PCIe Slot 1 Ambient" }, - { "TA0p", "Ambient Air" }, - { "TA1P", "Ambient 2" }, - { "TA1S", "PCIe Slot 1 PCB" }, - { "TA1p", "Ambient Air 2" }, - { "TA2P", "Ambient 3" }, - { "TA2S", "PCIe Slot 2 Ambient" }, - { "TA3S", "PCIe Slot 2 PCB" }, - { "TA0V", "Ambient" }, - { "TALP", "Ambient Light Proximity" }, - { "TaLC", "Airflow Left" }, - { "TaRC", "Airflow Right" }, - { "Ta0P", "Airflow Proximity" }, - /* Battery / enclosure */ - { "TB0T", "Enclosure Bottom" }, - { "TB1T", "Battery 1" }, - { "TB2T", "Battery 2" }, - { "TB3T", "Battery 3" }, - { "TBXT", "Battery" }, - { "Tb0P", "BLC Proximity" }, - /* CPU */ - { "TC0C", "CPU Core 1" }, - { "TC0D", "CPU Die" }, - { "TC0E", "CPU 1" }, - { "TC0F", "CPU 2" }, - { "TC0G", "CPU Package GPU" }, - { "TC0H", "CPU Heatsink" }, - { "TC0h", "CPU Heatsink" }, - { "TC0J", "CPU" }, - { "TC0P", "CPU Proximity" }, - { "TC0c", "CPU Core 1 PECI" }, - { "TC0d", "CPU Die PECI" }, - { "TC0p", "CPU Proximity" }, - { "TC1C", "CPU Core 2" }, - { "TC1c", "CPU Core 2 PECI" }, - { "TC1P", "CPU Proximity 2" }, - { "TC2C", "CPU Core 3" }, - { "TC2P", "CPU Proximity 3" }, - { "TC2c", "CPU Core 3 PECI" }, - { "TC3C", "CPU Core 4" }, - { "TC3P", "CPU Proximity 4" }, - { "TC3c", "CPU Core 4 PECI" }, - { "TC4C", "CPU Core 5" }, - { "TC5C", "CPU Core 6" }, - { "TC6C", "CPU Core 7" }, - { "TC7C", "CPU Core 8" }, - { "TC8C", "CPU Core 9" }, - { "TCGC", "PECI GPU" }, - { "TCGc", "PECI GPU" }, - { "TCHP", "Charger Proximity" }, - { "TCSA", "PECI SA" }, - { "TCSC", "PECI SA" }, - { "TCSc", "PECI SA" }, - { "TCTD", "CPU DTS" }, - { "TCXC", "PECI CPU" }, - { "TCXc", "PECI CPU" }, - { "TCPG", "CPU Package GPU" }, - { "TCXR", "CPU PECI DTS" }, - /* CPU dual-socket (Mac Pro) */ - { "TCAG", "CPU A Package" }, - { "TCAH", "CPU A Heatsink" }, - { "TCBG", "CPU B Package" }, - { "TCBH", "CPU B Heatsink" }, - /* GPU */ - { "TG0C", "GPU Core" }, - { "TG0D", "GPU Diode" }, - { "TG0H", "GPU Heatsink" }, - { "TG0M", "GPU Memory" }, - { "TG0P", "GPU Proximity" }, - { "TG0T", "GPU Diode" }, - { "TG0V", "GPU" }, - { "TG0d", "GPU Die" }, - { "TG0h", "GPU Heatsink" }, - { "TG0p", "GPU Proximity" }, - { "TGTV", "GPU" }, - { "TG1D", "GPU 2 Diode" }, - { "TG1H", "GPU 2 Heatsink" }, - { "TG1P", "GPU 2 Proximity" }, - { "TG1d", "GPU 2 Die" }, - { "TGVP", "GPU Memory Proximity" }, - /* Storage */ - { "TH0A", "SSD A" }, - { "TH0B", "SSD B" }, - { "TH0C", "SSD C" }, - { "TH0F", "SSD" }, - { "TH0O", "HDD" }, - { "TH0P", "HDD Proximity" }, - { "TH0R", "SSD" }, - { "TH0V", "SSD" }, - { "TH0a", "SSD A" }, - { "TH0b", "SSD B" }, - { "TH0c", "SSD C" }, - { "TH1O", "HDD 2" }, - { "TH1P", "HDD Bay 2" }, - { "TH2P", "HDD Bay 3" }, - { "TH3P", "HDD Bay 4" }, - { "Th0H", "Heatpipe 1" }, - { "Th0N", "SSD" }, - { "Th1H", "Heatpipe 2" }, - { "Th2H", "Heatpipe 3" }, - /* Thunderbolt */ - { "THSP", "Thunderbolt Proximity" }, - { "TI0P", "Thunderbolt 1" }, - { "TI0p", "Thunderbolt 1" }, - { "TI1P", "Thunderbolt 2" }, - { "TI1p", "Thunderbolt 2" }, - { "TTLD", "Thunderbolt Left" }, - { "TTRD", "Thunderbolt Right" }, - { "Te0T", "Thunderbolt Diode" }, - { "Te0t", "Thunderbolt Diode" }, - /* LCD */ - { "TL0P", "LCD Proximity" }, - { "TL0V", "LCD" }, - { "TL0p", "LCD Proximity" }, - { "TL1P", "LCD Panel 1" }, - { "TL1V", "LCD 1" }, - { "TL1p", "LCD Panel 1" }, - { "TL1v", "LCD 1" }, - { "TL2V", "LCD 2" }, - { "TLAV", "LCD" }, - { "TLBV", "LCD" }, - { "TLCV", "LCD" }, - /* Memory */ - { "TM0P", "Memory Proximity" }, - { "TM0S", "Memory Slot 1" }, - { "TM0p", "Memory Proximity" }, - { "TM1P", "Memory Riser A 2" }, - { "TM1S", "Memory Slot 2" }, - { "Tm0P", "Memory Proximity" }, - { "Tm0p", "Memory Proximity" }, - { "Tm1P", "Memory Proximity 2" }, - { "TMBS", "Memory Bank" }, - { "TMCD", "Memory DIMM" }, - /* Northbridge / MCH */ - { "TN0C", "Northbridge Core" }, - { "TN0D", "Northbridge Diode" }, - { "TN0H", "MCH Heatsink" }, - { "TN0P", "Northbridge Proximity" }, - { "TN1D", "MCH Die 2" }, - { "TN1P", "Northbridge Proximity 2" }, - /* PCH */ - { "TP0P", "PCH Proximity" }, - { "TP0p", "PCH Proximity" }, - { "TPCD", "PCH Die" }, - { "TPCd", "PCH Die" }, - /* Optical drive */ - { "TO0P", "Optical Drive" }, - { "TO0p", "Optical Drive" }, - /* Power supply */ - { "Tp0C", "Power Supply" }, - { "Tp0P", "Power Supply Proximity" }, - { "Tp1C", "Power Supply 2" }, - { "Tp1P", "Power Supply Component" }, - { "Tp1p", "Power Supply Component" }, - { "Tp2P", "Power Supply 2" }, - { "Tp2h", "Power Supply 2" }, - { "Tp2H", "Power Supply 2" }, - { "Tp3P", "Power Supply 3 Inlet" }, - { "Tp3h", "Power Supply 3" }, - { "Tp3H", "Power Supply 3" }, - { "Tp4P", "Power Supply 4" }, - { "Tp5P", "Power Supply 5" }, - /* Palm rest / trackpad */ - { "Ts0P", "Palm Rest" }, - { "Ts0S", "Memory Proximity" }, - { "Ts1P", "Palm Rest 2" }, - { "Ts1S", "Palm Rest 2" }, - /* Wireless */ - { "TW0P", "Wireless Proximity" }, - { "TW0p", "Wireless Proximity" }, - { "TBLR", "Bluetooth" }, - /* Camera */ - { "TS2P", "Camera Proximity" }, - { "TS2V", "Camera" }, - { "TS2p", "Camera Proximity" }, - /* Expansion */ - { "TS0C", "Expansion Slots" }, - { "TS0P", "Expansion Proximity" }, - { "TS0V", "Expansion" }, - { "TS0p", "Expansion Proximity" }, - /* Air vent */ - { "TV0P", "Air Vent" }, - /* VRM */ - { "Tv0S", "VRM 1" }, - { "Tv1S", "VRM 2" }, - /* Misc */ - { "TTF0", "Fan" }, - { "TMLB", "Logic Board" }, -}; -static const char * -asmc_temp_desc(const char *key) -{ - unsigned int i; - - for (i = 0; i < nitems(asmc_temp_descs); i++) { - if (strcmp(asmc_temp_descs[i].key, key) == 0) - return (asmc_temp_descs[i].desc); - } - return ("Temperature"); -} /* * Driver methods. @@ -428,121 +188,7 @@ asmc_try_probe(device_t dev) return (ENOMEM); } -/* - * The per-fan speed keys, selected by the high byte of a fan sysctl's arg2. - * Writable keys accept a new speed; the rest are reported only. - */ -#define ASMC_FAN_ARG2(which, fan) (((which) << 8) | (fan)) -#define ASMC_FAN_ARG2_WHICH(arg2) (((arg2) >> 8) & 0xff) -#define ASMC_FAN_ARG2_FAN(arg2) ((arg2) & 0xff) - -#define ASMC_FANSPEED_CUR 0 -#define ASMC_FANSPEED_SAFE 1 -#define ASMC_FANSPEED_MIN 2 -#define ASMC_FANSPEED_MAX 3 -#define ASMC_FANSPEED_TARGET 4 - -static const struct { - const char *key; - bool writable; -} asmc_fan_speed_keys[] = { - [ASMC_FANSPEED_CUR] = { ASMC_KEY_FANSPEED, false }, - [ASMC_FANSPEED_SAFE] = { ASMC_KEY_FANSAFESPEED, false }, - [ASMC_FANSPEED_MIN] = { ASMC_KEY_FANMINSPEED, true }, - [ASMC_FANSPEED_MAX] = { ASMC_KEY_FANMAXSPEED, true }, - [ASMC_FANSPEED_TARGET] = { ASMC_KEY_FANTARGETSPEED, true }, -}; - -/* The dev.asmc.n.fan.m leaves, in registration order. */ -static const struct { - const char *name; - const char *desc; - int ctlflags; - int (*handler)(SYSCTL_HANDLER_ARGS); - int which; - bool needs_safespeed; -} asmc_fan_sysctls[] = { - { "id", "Fan ID", CTLTYPE_STRING | CTLFLAG_RD, - asmc_mb_sysctl_fanid, 0, false }, - { "speed", "Fan speed in RPM", CTLTYPE_INT | CTLFLAG_RD, - asmc_mb_sysctl_fanspeed, ASMC_FANSPEED_CUR, false }, - { "safespeed", "Fan safe speed in RPM", CTLTYPE_INT | CTLFLAG_RD, - asmc_mb_sysctl_fanspeed, ASMC_FANSPEED_SAFE, true }, - { "minspeed", "Fan minimum speed in RPM", CTLTYPE_INT | CTLFLAG_RW, - asmc_mb_sysctl_fanspeed, ASMC_FANSPEED_MIN, false }, - { "maxspeed", "Fan maximum speed in RPM", CTLTYPE_INT | CTLFLAG_RW, - asmc_mb_sysctl_fanspeed, ASMC_FANSPEED_MAX, false }, - { "targetspeed", "Fan target speed in RPM", CTLTYPE_INT | CTLFLAG_RW, - asmc_mb_sysctl_fanspeed, ASMC_FANSPEED_TARGET, false }, - { "manual", "Fan manual mode (0=auto, 1=manual)", - CTLTYPE_INT | CTLFLAG_RW, asmc_mb_sysctl_fanmanual, 0, false }, -}; - -static void -asmc_sysctl_add_fan(device_t dev, struct sysctl_ctx_list *ctx) -{ - struct asmc_softc *sc = device_get_softc(dev); - char name[2]; - - sc->sc_fan_tree[0] = SYSCTL_ADD_NODE(ctx, - SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "fan", - CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Fan Root Tree"); - - for (int i = 1; i <= sc->sc_nfan; i++) { - int j = i - 1; - - name[0] = '0' + j; - name[1] = 0; - sc->sc_fan_tree[i] = SYSCTL_ADD_NODE(ctx, - SYSCTL_CHILDREN(sc->sc_fan_tree[0]), OID_AUTO, name, - CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Fan Subtree"); - - for (unsigned int k = 0; k < nitems(asmc_fan_sysctls); k++) { - if (asmc_fan_sysctls[k].needs_safespeed && - !sc->sc_has_safespeed) - continue; - - /* SYSCTL_ADD_PROC() asserts flags at compile time. */ - sysctl_add_oid(ctx, - SYSCTL_CHILDREN(sc->sc_fan_tree[i]), - OID_AUTO, asmc_fan_sysctls[k].name, - asmc_fan_sysctls[k].ctlflags | CTLFLAG_MPSAFE, - dev, ASMC_FAN_ARG2(asmc_fan_sysctls[k].which, j), - asmc_fan_sysctls[k].handler, "I", - asmc_fan_sysctls[k].desc, NULL); - } - } -} - -/* The dev.asmc.n.sms axes, selected by arg2. */ -static const struct { - const char *name; - const char *key; - const char *desc; -} asmc_sms_sysctls[] = { - { "x", ASMC_KEY_SMS_X, "Sudden Motion Sensor X value" }, - { "y", ASMC_KEY_SMS_Y, "Sudden Motion Sensor Y value" }, - { "z", ASMC_KEY_SMS_Z, "Sudden Motion Sensor Z value" }, -}; -static void -asmc_sysctl_add_sms(device_t dev, struct sysctl_ctx_list *ctx) -{ - struct asmc_softc *sc = device_get_softc(dev); - - sc->sc_sms_tree = SYSCTL_ADD_NODE(ctx, - SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "sms", - CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Sudden Motion Sensor"); - - for (unsigned int k = 0; k < nitems(asmc_sms_sysctls); k++) { - SYSCTL_ADD_PROC(ctx, - SYSCTL_CHILDREN(sc->sc_sms_tree), - OID_AUTO, asmc_sms_sysctls[k].name, - CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, - dev, k, asmc_mb_sysctl_sms, "I", - asmc_sms_sysctls[k].desc); - } -} /* Every key asmc_sms_init() touches; all must be present for SMS. */ static const char * const asmc_sms_required_keys[] = { @@ -558,116 +204,8 @@ static const char * const asmc_sms_required_keys[] = { ASMC_KEY_INTOK, }; -/* The ambient light sensors, selected by arg2. */ -#define ASMC_LIGHT_LEFT 0 -#define ASMC_LIGHT_RIGHT 1 - -static const char * const asmc_light_keys[] = { - [ASMC_LIGHT_LEFT] = ASMC_KEY_LIGHTLEFT, - [ASMC_LIGHT_RIGHT] = ASMC_KEY_LIGHTRIGHT, -}; - -/* The dev.asmc.n.system leaves, in registration order; len_min 0 = any. */ -static const struct { - const char *key; - const char *name; - const char *desc; - const char *fmt; - int ctlflags; - int arg2; - int (*handler)(SYSCTL_HANDLER_ARGS); - uint8_t len_min; - uint8_t len_max; -} asmc_system_sysctls[] = { - { ASMC_KEY_MSSD, "shutdown_cause", "Last shutdown cause (MSSD)", - "A", CTLTYPE_STRING | CTLFLAG_RD, 0, asmc_cause_sysctl, 0, 0 }, - { ASMC_KEY_MSSP, "sleep_cause", "Last sleep cause (MSSP)", - "A", CTLTYPE_STRING | CTLFLAG_RD, 1, asmc_cause_sysctl, 0, 0 }, - { ASMC_KEY_MSAL, "thermal_status", - "Thermal subsystem status flags (MSAL)", - "A", CTLTYPE_STRING | CTLFLAG_RD, 0, asmc_msal_sysctl, 0, 0 }, - { ASMC_KEY_CLKT, "time_of_day", - "Seconds since midnight per SMC clock (CLKT)", - "IU", CTLTYPE_UINT | CTLFLAG_RD, 0, asmc_clkt_sysctl, 0, 0 }, - { ASMC_KEY_MSPS, "power_state", "SMC power state index (MSPS)", - "IU", CTLTYPE_UINT | CTLFLAG_RD, 0, asmc_msps_sysctl, 1, 2 }, - { ASMC_KEY_RPLT, "board_id", "Apple internal board codename (RPlt)", - "A", CTLTYPE_STRING | CTLFLAG_RD, 0, asmc_rplt_sysctl, 0, 0 }, - { ASMC_KEY_RGEN, "chip_gen", - "Apple security chip generation (RGEN; 3=T2)", - "IU", CTLTYPE_UINT | CTLFLAG_RD, 0, asmc_rgen_sysctl, 0, 0 }, -}; - -static int -asmc_sysctl_add_system(device_t dev, struct sysctl_ctx_list *ctx) -{ - struct sysctl_oid *sys_tree; - - sys_tree = SYSCTL_ADD_NODE(ctx, - SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, - "system", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, - "System state and board identity"); - if (sys_tree == NULL) { - device_printf(dev, "failed to create system sysctl node\n"); - return (ENXIO); - } - - for (unsigned int k = 0; k < nitems(asmc_system_sysctls); k++) { - uint8_t len = 0; - - if (asmc_key_getinfo(dev, asmc_system_sysctls[k].key, - &len, NULL) != 0) - continue; - if (asmc_system_sysctls[k].len_min != 0 && - (len < asmc_system_sysctls[k].len_min || - len > asmc_system_sysctls[k].len_max)) - continue; - - /* SYSCTL_ADD_PROC() asserts flags at compile time. */ - sysctl_add_oid(ctx, SYSCTL_CHILDREN(sys_tree), - OID_AUTO, asmc_system_sysctls[k].name, - asmc_system_sysctls[k].ctlflags | CTLFLAG_MPSAFE, - dev, asmc_system_sysctls[k].arg2, - asmc_system_sysctls[k].handler, - asmc_system_sysctls[k].fmt, - asmc_system_sysctls[k].desc, NULL); - } - - return (0); -} - -/* Platform toggles under dev.asmc.n, each present only if its key reads. */ -static const struct { - const char *key; - const char *name; - const char *desc; - int (*handler)(SYSCTL_HANDLER_ARGS); -} asmc_platform_sysctls[] = { - { ASMC_KEY_AUPO, "auto_poweron", - "Auto power-on after AC power loss (0=off, 1=on)", - asmc_aupo_sysctl }, - { ASMC_KEY_MSLD, "sil", "Sleep indicator LED (0=off, 1=on)", - asmc_sil_sysctl }, -}; - -static void -asmc_sysctl_add_platform(device_t dev, struct sysctl_ctx_list *ctx) -{ - uint8_t buf[1]; - for (unsigned int k = 0; k < nitems(asmc_platform_sysctls); k++) { - if (asmc_key_read(dev, asmc_platform_sysctls[k].key, - buf, 1) != 0) - continue; - SYSCTL_ADD_PROC(ctx, - SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), - OID_AUTO, asmc_platform_sysctls[k].name, - CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, - dev, 0, asmc_platform_sysctls[k].handler, "I", - asmc_platform_sysctls[k].desc); - } -} static int asmc_attach(device_t dev) @@ -702,60 +240,10 @@ asmc_attach(device_t dev) asmc_detect_sensors(dev); asmc_sysctl_add_fan(dev, sysctlctx); + asmc_sysctl_add_temp(dev, sysctlctx); - /* - * dev.asmc.n.temp tree. - */ - sc->sc_temp_tree = SYSCTL_ADD_NODE(sysctlctx, - SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "temp", - CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Temperature sensors"); - - for (int i = 0; i < sc->sc_temp_count; i++) { - SYSCTL_ADD_PROC(sysctlctx, - SYSCTL_CHILDREN(sc->sc_temp_tree), - OID_AUTO, sc->sc_temp_sensors[i], - CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, i, - asmc_temp_sysctl, "I", - asmc_temp_desc(sc->sc_temp_sensors[i])); - } - - /* - * dev.asmc.n.light - */ if (sc->sc_has_light) { - sc->sc_light_tree = SYSCTL_ADD_NODE(sysctlctx, - SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "light", - CTLFLAG_RD | CTLFLAG_MPSAFE, 0, - "Keyboard backlight sensors"); - - SYSCTL_ADD_PROC(sysctlctx, - SYSCTL_CHILDREN(sc->sc_light_tree), - OID_AUTO, "left", - CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, - dev, ASMC_LIGHT_LEFT, - sc->sc_light_len == ASMC_LIGHT_LONGLEN ? - asmc_mbp_sysctl_light_left_10byte : - asmc_mbp_sysctl_light, - "I", "Keyboard backlight left sensor"); - - if (sc->sc_light_len != ASMC_LIGHT_LONGLEN && - asmc_key_getinfo(dev, ASMC_KEY_LIGHTRIGHT, - NULL, NULL) == 0) { - SYSCTL_ADD_PROC(sysctlctx, - SYSCTL_CHILDREN(sc->sc_light_tree), - OID_AUTO, "right", - CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, - dev, ASMC_LIGHT_RIGHT, - asmc_mbp_sysctl_light, "I", - "Keyboard backlight right sensor"); - } - - SYSCTL_ADD_PROC(sysctlctx, - SYSCTL_CHILDREN(sc->sc_light_tree), - OID_AUTO, "control", - CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, - dev, 0, asmc_mbp_sysctl_light_control, "I", - "Keyboard backlight brightness control"); + asmc_sysctl_add_light(dev, sysctlctx); sc->sc_kbd_bkl = backlight_register("asmc", dev); if (sc->sc_kbd_bkl == NULL) { @@ -1180,7 +668,7 @@ asmc_sensor_type_supported(const char *type) * Generic sensor value reader with automatic type conversion. * Reads an SMC key, detects its type, and converts to millivalue. */ -static int +int asmc_sensor_read(device_t dev, const char *key, int *millivalue) { uint8_t buf[2]; @@ -1215,52 +703,6 @@ asmc_sensor_read(device_t dev, const char *key, int *millivalue) return (0); } -/* - * Generic sensor sysctl handler for voltage/current/power/light sensors. - * arg2 encodes: sensor_type (high byte) | sensor_index (low byte) - * Sensor types: 'V'=voltage, 'I'=current, 'P'=power, 'L'=light - */ -static int -asmc_sensor_sysctl(SYSCTL_HANDLER_ARGS) -{ - device_t dev = (device_t) arg1; - struct asmc_softc *sc = device_get_softc(dev); - int error, val; - int sensor_type = (arg2 >> 8) & 0xFF; - int sensor_idx = arg2 & 0xFF; - const char *key = NULL; - - /* Select sensor based on type and index */ - switch (sensor_type) { - case 'V': /* Voltage */ - if (sensor_idx < sc->sc_voltage_count) - key = sc->sc_voltage_sensors[sensor_idx]; - break; - case 'I': /* Current */ - if (sensor_idx < sc->sc_current_count) - key = sc->sc_current_sensors[sensor_idx]; - break; - case 'P': /* Power */ - if (sensor_idx < sc->sc_power_count) - key = sc->sc_power_sensors[sensor_idx]; - break; - case 'L': /* Light */ - if (sensor_idx < sc->sc_light_count) - key = sc->sc_light_sensors[sensor_idx]; - break; - default: - return (EINVAL); - } - - if (key == NULL) - return (ENOENT); - - error = asmc_sensor_read(dev, key, &val); - if (error != 0) - return (error); - - return (sysctl_handle_int(oidp, &val, 0, req)); -} static bool asmc_match_sp78(const char *key __unused, const char *type) @@ -1517,232 +959,12 @@ asmc_fan_count(device_t dev) return (buf[0]); } -static int -asmc_fan_getvalue(device_t dev, const char *key, int fan) -{ - struct asmc_softc *sc = device_get_softc(dev); - int speed; - uint8_t buf[4]; - char fankey[5]; - char type[ASMC_TYPELEN + 1]; - snprintf(fankey, sizeof(fankey), key, fan); - - /* - * T2 Macs use IEEE 754 float ("flt ") for fan speeds, - * stored little-endian in the MMIO data register. - * Standard Macs use s14.2 fixed-point ("fpe2", 2 bytes). - */ - if (sc->sc_is_t2 && - asmc_key_getinfo(dev, fankey, NULL, type) == 0 && - strncmp(type, "flt ", 4) == 0) { - if (asmc_key_read(dev, fankey, buf, 4) != 0) - return (-1); - speed = (int)asmc_float_to_u32(le32dec(buf)); - } else { - if (asmc_key_read(dev, fankey, buf, 2) != 0) - return (-1); - speed = (buf[0] << 6) | (buf[1] >> 2); - } - - return (speed); -} - -static char * -asmc_fan_getstring(device_t dev, const char *key, int fan, uint8_t *buf, - uint8_t buflen) -{ - char fankey[5]; - char *desc; - - snprintf(fankey, sizeof(fankey), key, fan); - if (asmc_key_read(dev, fankey, buf, buflen) != 0) - return (NULL); - desc = buf + 4; - - return (desc); -} - -static int -asmc_fan_setvalue(device_t dev, const char *key, int fan, int speed) -{ - struct asmc_softc *sc = device_get_softc(dev); - uint8_t buf[4]; - char fankey[5]; - char type[ASMC_TYPELEN + 1]; - - snprintf(fankey, sizeof(fankey), key, fan); - - if (sc->sc_is_t2 && - asmc_key_getinfo(dev, fankey, NULL, type) == 0 && - strncmp(type, "flt ", 4) == 0) { - uint32_t fval; - speed = MAX(speed, 0); - speed = MIN(speed, 65535); - fval = asmc_u32_to_float((uint32_t)speed); - le32enc(buf, fval); - if (asmc_key_write(dev, fankey, buf, 4) != 0) - return (-1); - } else { - speed *= 4; - buf[0] = speed >> 8; - buf[1] = speed; - if (asmc_key_write(dev, fankey, buf, 2) != 0) - return (-1); - } - - return (0); -} - -static int -asmc_mb_sysctl_fanspeed(SYSCTL_HANDLER_ARGS) -{ - device_t dev = (device_t)arg1; - int which = ASMC_FAN_ARG2_WHICH(arg2); - int fan = ASMC_FAN_ARG2_FAN(arg2); - int error; - int32_t v; - - v = asmc_fan_getvalue(dev, asmc_fan_speed_keys[which].key, fan); - error = sysctl_handle_int(oidp, &v, 0, req); - - if (error == 0 && req->newptr != NULL && - asmc_fan_speed_keys[which].writable) { - unsigned int newspeed = v; - asmc_fan_setvalue(dev, asmc_fan_speed_keys[which].key, fan, - newspeed); - } - - return (error); -} - -static int -asmc_mb_sysctl_fanid(SYSCTL_HANDLER_ARGS) -{ - uint8_t buf[16]; - device_t dev = (device_t)arg1; - int fan = ASMC_FAN_ARG2_FAN(arg2); - int error = true; - char *desc; - - desc = asmc_fan_getstring(dev, ASMC_KEY_FANID, fan, buf, sizeof(buf)); - - if (desc != NULL) - error = sysctl_handle_string(oidp, desc, 0, req); - - return (error); -} - -static int -asmc_mb_sysctl_fanmanual(SYSCTL_HANDLER_ARGS) -{ - device_t dev = (device_t)arg1; - struct asmc_softc *sc = device_get_softc(dev); - int fan = ASMC_FAN_ARG2_FAN(arg2); - int error; - int32_t v; - uint8_t buf[2]; - uint16_t val; - char fmkey[5]; - - /* - * T2 Macs use per-fan F%dMd keys (1 byte each). - * Standard Macs use FS! bitmask (2 bytes). - */ - snprintf(fmkey, sizeof(fmkey), ASMC_KEY_FANMANUAL_T2, fan); - if (sc->sc_is_t2 && - asmc_key_getinfo(dev, fmkey, NULL, NULL) == 0) { - error = asmc_key_read(dev, fmkey, buf, 1); - if (error != 0) - return (error); - v = buf[0] ? 1 : 0; - - error = sysctl_handle_int(oidp, &v, 0, req); - if (error == 0 && req->newptr != NULL) { - if (v != 0 && v != 1) - return (EINVAL); - buf[0] = (uint8_t)v; - error = asmc_key_write(dev, fmkey, buf, 1); - } - return (error); - } - - /* Read current FS! bitmask (asmc_key_read locks internally) */ - error = asmc_key_read(dev, ASMC_KEY_FANMANUAL, buf, sizeof(buf)); - if (error != 0) - return (error); - - /* Extract manual bit for this fan (big-endian) */ - val = (buf[0] << 8) | buf[1]; - v = (val >> fan) & 0x01; - - /* Let sysctl handle the value */ - error = sysctl_handle_int(oidp, &v, 0, req); - - if (error == 0 && req->newptr != NULL) { - /* Validate input (0 = auto, 1 = manual) */ - if (v != 0 && v != 1) - return (EINVAL); - /* Read-modify-write of FS! bitmask */ - error = asmc_key_read(dev, ASMC_KEY_FANMANUAL, buf, - sizeof(buf)); - if (error == 0) { - val = (buf[0] << 8) | buf[1]; - - /* Modify single bit */ - if (v) - val |= (1 << fan); /* Set to manual */ - else - val &= ~(1 << fan); /* Set to auto */ - - /* Write back */ - buf[0] = val >> 8; - buf[1] = val & 0xff; - error = asmc_key_write(dev, ASMC_KEY_FANMANUAL, buf, - sizeof(buf)); - } - } - - return (error); -} - -/* - * Temperature functions. - */ -static int -asmc_temp_getvalue(device_t dev, const char *key) -{ - uint8_t buf[2]; - - /* - * Check for invalid temperatures. - */ - if (asmc_key_read(dev, key, buf, sizeof(buf)) != 0) - return (-1); - - return (buf[0]); -} - -static int -asmc_temp_sysctl(SYSCTL_HANDLER_ARGS) -{ - device_t dev = (device_t)arg1; - struct asmc_softc *sc = device_get_softc(dev); - int error, val; - - if (arg2 < 0 || arg2 >= sc->sc_temp_count) - return (EINVAL); - - val = asmc_temp_getvalue(dev, sc->sc_temp_sensors[arg2]); - error = sysctl_handle_int(oidp, &val, 0, req); - - return (error); -} /* * Sudden Motion Sensor functions. */ -static int +int asmc_sms_read(device_t dev, const char *key, int16_t *val) { uint8_t buf[2]; @@ -1853,150 +1075,7 @@ asmc_sms_task(void *arg, int pending) devctl_notify("ACPI", "asmc", "SMS", notify); } -static int -asmc_mb_sysctl_sms(SYSCTL_HANDLER_ARGS) -{ - device_t dev = (device_t)arg1; - int error; - int16_t val; - int32_t v; - - asmc_sms_read(dev, asmc_sms_sysctls[arg2].key, &val); - v = (int32_t)val; - error = sysctl_handle_int(oidp, &v, 0, req); - - return (error); -} - -static int -asmc_mbp_sysctl_light(SYSCTL_HANDLER_ARGS) -{ - device_t dev = (device_t)arg1; - uint8_t buf[6]; - int error; - int32_t v; - - asmc_key_read(dev, asmc_light_keys[arg2], buf, sizeof(buf)); - v = buf[2]; - error = sysctl_handle_int(oidp, &v, 0, req); - - return (error); -} - -static int -asmc_mbp_sysctl_light_control(SYSCTL_HANDLER_ARGS) -{ - device_t dev = (device_t)arg1; - struct asmc_softc *sc = device_get_softc(dev); - uint8_t buf[2]; - int error; - int v; - - v = sc->sc_light_control; - error = sysctl_handle_int(oidp, &v, 0, req); - - if (error == 0 && req->newptr != NULL) { - if (v < 0 || v > 255) - return (EINVAL); - sc->sc_light_control = v; - sc->sc_kbd_bkl_level = v * 100 / 255; - buf[0] = sc->sc_light_control; - buf[1] = 0x00; - asmc_key_write(dev, ASMC_KEY_LIGHTVALUE, buf, sizeof(buf)); - } - return (error); -} - -static int -asmc_mbp_sysctl_light_left_10byte(SYSCTL_HANDLER_ARGS) -{ - device_t dev = (device_t)arg1; - uint8_t buf[10]; - int error; - uint32_t v; - *** 1484 LINES SKIPPED ***