Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys
       [not found] ` <20261204131619.5059-15-atharvatiwarilinuxdev@gmail.com>
@ 2026-12-04 13:40   ` Sasha Finkelstein
  0 siblings, 0 replies; 3+ messages in thread
From: Sasha Finkelstein @ 2026-12-04 13:40 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-acpi,
	linux-gpio, asahi, linux-arm-kernel, linux-hwmon, linux-leds, mfd,
	platform-driver-x86, linux-pm

On Dec 4, 2026, at 14:12, Atharva Tiwari <atharvatiwarilinuxdev@gmail.com> wrote:
> 
> Add a /dev/smc device so userspace can talk to the SMC
> directly. Some keys that need to be written aren't handled by
> any driver, or affect several drivers at once, so they
> can't be exposed cleanly through the kernel interfaces.
> 
> Keys already managed by kernel drivers can't be written this
> way, to avoid conflicts.
> 
> [...]
> + switch (cmd) {
> + case IOCTL_SMC_READ: {
> + struct ioctl_smc_rw_payload payload;
> + struct apple_smc_key_info info;
> +
> + if (copy_from_user(&payload, argp, sizeof(payload)))
> + return -EFAULT;
> +
> + ret = apple_smc_get_key_info(smc, payload.key, &info);
> + if (ret < 0)
> + return ret;
> +
> + if (payload.size != info.size)
> + return -EINVAL;
> +
> + if (payload.size > 32 || !(info.flags & APPLE_SMC_READABLE))
> + return -EINVAL;
> +

This needs a key whitelist too, AS has read-sensitive keys.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power
       [not found] ` <20261204131619.5059-11-atharvatiwarilinuxdev@gmail.com>
@ 2026-12-04 14:42   ` Sasha Finkelstein
  2026-12-04 19:41     ` Atharva Tiwari
  0 siblings, 1 reply; 3+ messages in thread
From: Sasha Finkelstein @ 2026-12-04 14:42 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Andre Eikmeyer,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, linux-kernel, linux-acpi,
	asahi, linux-arm-kernel, mfd, platform-driver-x86, linux-pm

On Dec 4, 2026, at 14:12, Atharva Tiwari <atharvatiwarilinuxdev@gmail.com> wrote:
> 
> Make macsmc-power work on Intel Macs, as a replacement for
> acpi-sbs. It exposes a lot more sensors than acpi-sbs, such
> as voltage, current, power, temperature, charge and health
> info, and also the adapter state.
> 
> [...]
> 
> +#include <linux/acpi.h>

I do not see a dependency on CONFIG_ACPI. And it should not have one
anyway, AS does not need ACPI.

> +static int macsmc_battery_acpi_read(struct apple_smc *smc, smc_key key, int *val,
> + int scale)
> +{
> + int ret;
> + struct apple_smc_key_info info;
> +
> + ret = apple_smc_get_key_info(smc, key, &info);
> + if (ret)
> + return ret;
> +
> + switch (info.type_code) {
> + /* 32-bit IEEE 754 float */
> + case __SMC_KEY('f', 'l', 't', ' '): {
> + int flt_ = 0;
> +
> + ret = macsmc_battery_acpi_read_f32_scaled(smc, key, &flt_, scale);
> + if (ret)
> + return ret;
> +
> + *val = flt_;
> + break;
> + }
> +
> + /* 3.13 fixed point decimal */

Is Apple actually using every single one of those formats?


> case POWER_SUPPLY_PROP_VOLTAGE_NOW:
> ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &vu16);
> - val->intval = vu16 * 1000;
> + if (power->smc->is_acpi)
> + val->intval = swab16(vu16) * 1000;
> + else
> + val->intval = vu16 * 1000;
> break;

This pattern happens way too often to leave open-coded.


> case POWER_SUPPLY_PROP_POWER_NOW:
> - ret = apple_smc_read_s32(power->smc, SMC_KEY(B0AP), &vs32);
> - val->intval = vs32 * 1000;
> + if (power->smc->is_acpi) {
> + if (power->has_b0ap) {
> + ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(B0AP),
> + &val->intval, 1000000);
> + if (ret < 0)
> + return ret;
> +
> + val->intval = -val->intval;
> + } else {
> + ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &vu16);
> + if (ret < 0)
> + return ret;
> +
> + ret = apple_smc_read_s16(power->smc, SMC_KEY(B0AC), &vs16);
> + if (ret < 0)
> + return ret;
> +
> + val->intval = (s16)swab16(vs16) * swab16(vu16);
> + }
> + } else {
> + ret = apple_smc_read_s32(power->smc, SMC_KEY(B0AP), &vs32);
> + val->intval = vs32 * 1000;
> + }
> break;

Please put this somewhere else and not inline

> switch (psp) {
> case POWER_SUPPLY_PROP_ONLINE:
> - ret = apple_smc_read_u32(power->smc, SMC_KEY(CHIS), &vu32);
> - val->intval = !!vu32;
> + if (power->smc->is_acpi) {
> + if (power->has_battery) {
> + acpi_status status;
> + unsigned long long adapter_status;
> +
> + status = acpi_evaluate_integer(power->adapter->handle,
> + "_PSR", NULL, &adapter_status);
> + if (ACPI_FAILURE(status))
> + return -EIO;
> +
> + val->intval = !!adapter_status;
> + } else
> + val->intval = 1;
> + } else {
> + ret = apple_smc_read_u32(power->smc, SMC_KEY(CHIS), &vu32);
> + val->intval = !!vu32;
> + }
> + break;

Same

> + if (smc->is_acpi) {
> + props[nprops++] = POWER_SUPPLY_PROP_STATUS;
> + props[nprops++] = POWER_SUPPLY_PROP_PRESENT;
> + props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_CURRENT_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_POWER_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_CAPACITY;
> + props[nprops++] = POWER_SUPPLY_PROP_CAPACITY_LEVEL;
> + props[nprops++] = POWER_SUPPLY_PROP_TEMP;
> + props[nprops++] = POWER_SUPPLY_PROP_CYCLE_COUNT;
> + props[nprops++] = POWER_SUPPLY_PROP_HEALTH;
> + props[nprops++] = POWER_SUPPLY_PROP_SCOPE;
> 
> [...]
> 
> + props[nprops++] = POWER_SUPPLY_PROP_STATUS;
> + props[nprops++] = POWER_SUPPLY_PROP_PRESENT;
> + props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_CURRENT_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_POWER_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_CAPACITY;
> + props[nprops++] = POWER_SUPPLY_PROP_CAPACITY_LEVEL;
> + props[nprops++] = POWER_SUPPLY_PROP_TEMP;
> + props[nprops++] = POWER_SUPPLY_PROP_CYCLE_COUNT;
> + props[nprops++] = POWER_SUPPLY_PROP_HEALTH;
> + props[nprops++] = POWER_SUPPLY_PROP_SCOPE;

They are the same picture




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power
  2026-12-04 14:42   ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Sasha Finkelstein
@ 2026-12-04 19:41     ` Atharva Tiwari
  0 siblings, 0 replies; 3+ messages in thread
From: Atharva Tiwari @ 2026-12-04 19:41 UTC (permalink / raw)
  To: k
  Cc: aditya.garg, alexandre.belloni, andy, asahi,
	atharvatiwarilinuxdev, bhelgaas, bp, brgl, dave.hansen, dev,
	dlechner, dmitry.kasatkin, eric.snowberg, griffin, hansg, hpa,
	ilpo.jarvinen, j, jarkko, jic23, jmorris, lee, lenb, linusw,
	linux-acpi, linux-arm-kernel, linux-kernel, linux-pm, linux, mfd,
	mingo, neal, nuno.sa, paul, pavel, platform-driver-x86, pv4k,
	rafael, roberto.sassu, sidemantoine, sre, sven, tglx, wim, x86,
	zohar

> I do not see a dependency on CONFIG_ACPI. And it should not have one
> anyway, AS does not need ACPI.

I agree that AS does not require ACPI for anything but
Intel macs require it for adapter interrupts so i will
just guard it using CONFIG_MACSMC_ACPI.

> Is Apple actually using every single one of those formats?

Yes, most of these formats are used by very old Intel Macs (pre-2015).



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04 19:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com>
     [not found] ` <20261204131619.5059-15-atharvatiwarilinuxdev@gmail.com>
2026-12-04 13:40   ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Sasha Finkelstein
     [not found] ` <20261204131619.5059-11-atharvatiwarilinuxdev@gmail.com>
2026-12-04 14:42   ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Sasha Finkelstein
2026-12-04 19:41     ` Atharva Tiwari

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox