Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys First draft of drivers for the Apple System Management C...
details: https://anonhg.NetBSD.org/src/rev/0f0153865661
branches: trunk
changeset: 328370:0f0153865661
user: riastradh <riastradh%NetBSD.org@localhost>
date: Tue Apr 01 17:47:36 2014 +0000
description:
First draft of drivers for the Apple System Management Controller.
Device interface derived by reading the Linux driver source code and
<http:///www.parhelia.ch/blog/statics/k3_keys.html> as of 2012-12-05.
Includes support for attaching fan and temperature sensors to sysmon.
No accelerometer yet.
Compile-tested only, based on some run-testing of experiments from
userland. Module attachment is not quite finished, so it won't work
yet.
diffstat:
sys/conf/files | 22 +-
sys/dev/acpi/apple_smc_acpi.c | 145 +++++++++
sys/dev/acpi/files.acpi | 6 +-
sys/dev/ic/apple_smc.c | 524 +++++++++++++++++++++++++++++++++
sys/dev/ic/apple_smc.h | 109 ++++++
sys/dev/ic/apple_smc_fan.c | 406 +++++++++++++++++++++++++
sys/dev/ic/apple_smc_temp.c | 361 ++++++++++++++++++++++
sys/dev/ic/apple_smcreg.h | 54 +++
sys/dev/ic/apple_smcvar.h | 70 ++++
sys/modules/apple_smc/Makefile | 17 +
sys/modules/apple_smc/apple_smc.ioconf | 13 +
11 files changed, 1725 insertions(+), 2 deletions(-)
diffs (truncated from 1789 to 300 lines):
diff -r ddf5f2c8e862 -r 0f0153865661 sys/conf/files
--- a/sys/conf/files Tue Apr 01 17:34:44 2014 +0000
+++ b/sys/conf/files Tue Apr 01 17:47:36 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1087 2014/03/19 15:26:42 nonaka Exp $
+# $NetBSD: files,v 1.1088 2014/04/01 17:47:36 riastradh Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20100430
@@ -1095,6 +1095,26 @@
device smsh: arp, ether, ifnet, mii
file dev/ic/lan9118.c smsh
+# Apple System Management Controller
+#
+device applesmc {}
+file dev/ic/apple_smc.c applesmc
+
+# Apple SMC fan sensors and control
+device applesmcfan: applesmc, sysmon_envsys
+attach applesmcfan at applesmc with apple_smc_fan
+file dev/ic/apple_smc_fan.c applesmcfan
+
+# Apple SMC temperature sensors
+device applesmctemp: applesmc, sysmon_envsys
+attach applesmctemp at applesmc with apple_smc_temp
+file dev/ic/apple_smc_temp.c applesmctemp
+
+# Apple SMC accelerometer
+#device applesmcaccel: applesmc, sysmon_envsys
+#attach applesmcaccel at applesmc with apple_smc_accel
+#file dev/ic/apple_smc_accel.c applesmcaccel
+
# DRM - Direct Rendering Infrastructure: dev/drm
define drm {}
include "external/bsd/drm/conf/files.drm"
diff -r ddf5f2c8e862 -r 0f0153865661 sys/dev/acpi/apple_smc_acpi.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/apple_smc_acpi.c Tue Apr 01 17:47:36 2014 +0000
@@ -0,0 +1,145 @@
+/* $NetBSD: apple_smc_acpi.c,v 1.1 2014/04/01 17:47:36 riastradh Exp $ */
+
+/*
+ * Apple System Management Controller: ACPI Attachment
+ */
+
+/*-
+ * Copyright (c) 2013 Taylor R. Campbell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: apple_smc_acpi.c,v 1.1 2014/04/01 17:47:36 riastradh Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#include <dev/ic/apple_smcreg.h>
+#include <dev/ic/apple_smcvar.h>
+
+#define _COMPONENT ACPI_RESOURCE_COMPONENT
+ACPI_MODULE_NAME ("apple_smc_acpi")
+
+struct apple_smc_acpi_softc {
+ struct apple_smc_tag sc_smc;
+};
+
+static int apple_smc_acpi_match(device_t, cfdata_t, void *);
+static void apple_smc_acpi_attach(device_t, device_t, void *);
+static int apple_smc_acpi_detach(device_t, int);
+
+CFATTACH_DECL_NEW(apple_smc_acpi, sizeof(struct apple_smc_acpi_softc),
+ apple_smc_acpi_match, apple_smc_acpi_attach, apple_smc_acpi_detach, NULL);
+
+static const char *const apple_smc_ids[] = {
+ "APP0001",
+ NULL
+};
+
+static int
+apple_smc_acpi_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct acpi_attach_args *aa = aux;
+
+ if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+ return 0;
+
+ if (!acpi_match_hid(aa->aa_node->ad_devinfo, apple_smc_ids))
+ return 0;
+
+ return 1;
+}
+
+static void
+apple_smc_acpi_attach(device_t parent, device_t self, void *aux)
+{
+ struct apple_smc_acpi_softc *sc = device_private(self);
+ struct apple_smc_tag *smc = &sc->sc_smc;
+ struct acpi_attach_args *aa = aux;
+ struct acpi_resources res;
+ struct acpi_io *io;
+ int rv;
+
+ smc->smc_dev = self;
+
+ aprint_normal("\n");
+ aprint_naive("\n");
+
+ rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
+ &res, &acpi_resource_parse_ops_default);
+ if (ACPI_FAILURE(rv)) {
+ aprint_error_dev(self, "couldn't parse SMC resources: %s\n",
+ AcpiFormatException(rv));
+ goto out0;
+ }
+
+ io = acpi_res_io(&res, 0);
+ if (io == NULL) {
+ aprint_error_dev(self, "no I/O resource\n");
+ goto out1;
+ }
+
+ if (io->ar_length < APPLE_SMC_REGSIZE) {
+ aprint_error_dev(self, "I/O resources too small: %"PRId32"\n",
+ io->ar_length);
+ goto out1;
+ }
+
+ if (bus_space_map(aa->aa_iot, io->ar_base, io->ar_length, 0,
+ &smc->smc_bsh) != 0) {
+ aprint_error_dev(self, "unable to map I/O registers\n");
+ goto out1;
+ }
+
+ smc->smc_bst = aa->aa_iot;
+ smc->smc_size = io->ar_length;
+
+ apple_smc_attach(smc);
+
+out1: acpi_resource_cleanup(&res);
+out0: return;
+}
+
+static int
+apple_smc_acpi_detach(device_t self, int flags)
+{
+ struct apple_smc_acpi_softc *sc = device_private(self);
+ struct apple_smc_tag *smc = &sc->sc_smc;
+ int error;
+
+ if (smc->smc_size != 0) {
+ error = apple_smc_detach(smc, flags);
+ if (error)
+ return error;
+
+ bus_space_unmap(smc->smc_bst, smc->smc_bsh, smc->smc_size);
+ smc->smc_size = 0;
+ }
+
+ return 0;
+}
diff -r ddf5f2c8e862 -r 0f0153865661 sys/dev/acpi/files.acpi
--- a/sys/dev/acpi/files.acpi Tue Apr 01 17:34:44 2014 +0000
+++ b/sys/dev/acpi/files.acpi Tue Apr 01 17:47:36 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.acpi,v 1.93 2012/01/22 06:44:28 christos Exp $
+# $NetBSD: files.acpi,v 1.94 2014/04/01 17:47:36 riastradh Exp $
include "dev/acpi/acpica/files.acpica"
@@ -206,4 +206,8 @@
attach fujhk at acpinodebus
file dev/acpi/fujhk_acpi.c fujhk
+# Apple SMC
+attach applesmc at acpinodebus with apple_smc_acpi
+file dev/acpi/apple_smc_acpi.c apple_smc_acpi
+
include "dev/acpi/wmi/files.wmi"
diff -r ddf5f2c8e862 -r 0f0153865661 sys/dev/ic/apple_smc.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/apple_smc.c Tue Apr 01 17:47:36 2014 +0000
@@ -0,0 +1,524 @@
+/* $NetBSD: apple_smc.c,v 1.1 2014/04/01 17:47:36 riastradh Exp $ */
+
+/*
+ * Apple System Management Controller
+ */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: apple_smc.c,v 1.1 2014/04/01 17:47:36 riastradh Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/errno.h>
+#include <sys/kmem.h>
+#include <sys/mutex.h>
+#if 0 /* XXX sysctl */
+#include <sys/sysctl.h>
+#endif
+#include <sys/systm.h>
+
+#include <dev/ic/apple_smc.h>
+#include <dev/ic/apple_smcreg.h>
+#include <dev/ic/apple_smcvar.h>
+
+static void apple_smc_rescan1(struct apple_smc_tag *,
+ struct apple_smc_attach_args *,
+ const char *, const char *, device_t *);
+static uint8_t apple_smc_bus_read_1(struct apple_smc_tag *, bus_size_t);
+static void apple_smc_bus_write_1(struct apple_smc_tag *, bus_size_t,
+ uint8_t);
+static int apple_smc_read_data(struct apple_smc_tag *, uint8_t *);
+static int apple_smc_write(struct apple_smc_tag *, bus_size_t, uint8_t);
+static int apple_smc_write_cmd(struct apple_smc_tag *, uint8_t);
+static int apple_smc_write_data(struct apple_smc_tag *, uint8_t);
+static int apple_smc_begin(struct apple_smc_tag *, uint8_t,
+ const char *, uint8_t);
+static int apple_smc_input(struct apple_smc_tag *, uint8_t,
+ const char *, void *, uint8_t);
+static int apple_smc_output(struct apple_smc_tag *, uint8_t,
+ const char *, const void *, uint8_t);
+
+void
+apple_smc_attach(struct apple_smc_tag *smc)
+{
+
+ mutex_init(&smc->smc_lock, MUTEX_DEFAULT, IPL_NONE);
+
+#if 0 /* XXX sysctl */
+ apple_smc_sysctl_setup(smc);
+#endif
+
+ (void)apple_smc_rescan(smc, NULL, NULL);
+}
+
+int
+apple_smc_rescan(struct apple_smc_tag *smc, const char *ifattr,
+ const int *locators)
+{
+ struct apple_smc_attach_args asa;
+
+ (void)locators; /* ignore */
+
+ (void)memset(&asa, 0, sizeof asa);
+ asa.asa_smc = smc;
Home |
Main Index |
Thread Index |
Old Index