Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Jun 2015 21:15:53 -0400
From:      Anthony Jenkins <Anthony.B.Jenkins@att.net>
To:        Ian Smith <smithi@nimnet.asn.au>, Warner Losh <imp@bsdimp.com>
Cc:        freebsd-acpi@freebsd.org
Subject:   Re: [PATCH] ACPI CMOS region support rev. 6
Message-ID:  <558CA7C9.9000304@att.net>
In-Reply-To: <558CA785.1050904@att.net>
References:  <20150222180817.GD27984@strugglingcoder.info> <54EB8C21.2080600@att.net> <2401337.2oUs7iAbtB@ralph.baldwin.cx> <54EF3D5D.4010106@att.net> <20150227222203.P38620@sola.nimnet.asn.au> <20150228125857.D1277@besplex.bde.org> <54F14368.4020807@att.net> <20150302002647.W42658@sola.nimnet.asn.au> <54F5E53D.1090601@att.net> <20150306025800.U46361@sola.nimnet.asn.au> <54F9D7E6.4050807@att.net> <5504FF32.3020202@att.net> <20150317001401.X22641@sola.nimnet.asn.au> <5506F00A.3030708@att.net> <5506FBE3.1000009@att.net> <20150317041624.K22641@sola.nimnet.asn.au> <55073442.5060005@att.net> <20150317222704.K22641@sola.nimnet.asn.au> <550825DE.7030406@att.net> <56B494A3-2058-4B7B-8183-646A46753A53@bsdimp.com> <5509A282.6070207@att.net> <D1E7A1AE-51FD-4BFB-A861-13E16F95BB77@bsdimp.com> <20150319184348.X22641@sola.nimnet.asn.au> <550ACAEC.3060808@att.net> <20150320002950.T22641@sola.nimnet.asn.au> <550AD9B7.4090508@att.net> <558CA785.1050904@att.net>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------050805090500090807050701
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit

...and of course I forget the attachment...

On 06/25/15 21:14, Anthony Jenkins wrote:
> Sooo here's the new and improved rev. 6, "new and improved" because it
> increases the diff line count by 332%.
>> [ajenkins@ajenkins-hplaptop /usr/src]$ wc -l atrtc_c_rev5.diff
>> atrtc_rev6.diff
>>      220 atrtc_c_rev5.diff
>>      731 atrtc_rev6.diff
> This is to satisfy the request to split the atrtc.c driver into a "core"
> part and "bus" parts:
>> Looking at patch 5:
>>
>> You need to rework this so there’s an atrtc_acpi.c. Put all the ACPI attachment in there. You should also split off the little bit that’s ISA-specific into atrtc_isa. Once you do that, we can talk.
>>
>> Warner
> I actually finished this patch a couple months ago and have been running
> it on my laptop, I just don't see the point...maybe Warner could
> elaborate on the rationale for his request?  At the very least, this
> should be two commits - the functional change and the refactorization
> request.
>
> I may have also added Ian's request for verbosity tweaks, but it's been
> a while... I don't see any CMOS logging noise FWIW.
>
> Thanks,
> Anthony
>
>


--------------050805090500090807050701
Content-Type: text/x-patch;
 name="atrtc_rev6.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="atrtc_rev6.diff"

Index: sys/conf/files.i386
===================================================================
--- sys/conf/files.i386	(revision 284815)
+++ sys/conf/files.i386	(working copy)
@@ -577,8 +577,10 @@
 x86/iommu/intel_quirks.c	optional acpi acpi_dmar pci
 x86/iommu/intel_utils.c		optional acpi acpi_dmar pci
 x86/isa/atpic.c			optional atpic
-x86/isa/atrtc.c			standard
-x86/isa/clock.c			standard
+x86/isa/atrtc.c			standard native
+x86/isa/atrtc_isa.c		standard isa atrtc
+#x86/isa/atrtc_acpi.c		optional atrtc acpi
+x86/isa/clock.c			optional native
 x86/isa/elcr.c			optional atpic | apic
 x86/isa/isa.c			optional isa
 x86/isa/isa_dma.c		optional isa
Index: sys/conf/files.amd64
===================================================================
--- sys/conf/files.amd64	(revision 284815)
+++ sys/conf/files.amd64	(working copy)
@@ -583,6 +583,8 @@
 x86/iommu/intel_utils.c		optional	acpi acpi_dmar pci
 x86/isa/atpic.c			optional	atpic isa
 x86/isa/atrtc.c			standard
+x86/isa/atrtc_isa.c		standard	
+x86/isa/atrtc_acpi.c		standard
 x86/isa/clock.c			standard
 x86/isa/elcr.c			optional	atpic isa | mptable
 x86/isa/isa.c			standard
Index: sys/x86/isa/atrtc.c
===================================================================
--- sys/x86/isa/atrtc.c	(revision 284815)
+++ sys/x86/isa/atrtc.c	(working copy)
@@ -42,21 +42,24 @@
 #include <sys/kernel.h>
 #include <sys/module.h>
 #include <sys/proc.h>
-#include <sys/rman.h>
 #include <sys/timeet.h>
 
 #include <isa/rtc.h>
+#include <machine/intr_machdep.h>
+#include "clock_if.h"
+#include "atrtcvar.h"
+
 #ifdef DEV_ISA
 #include <isa/isareg.h>
 #include <isa/isavar.h>
 #endif
-#include <machine/intr_machdep.h>
-#include "clock_if.h"
 
 #define	RTC_LOCK	do { if (!kdb_active) mtx_lock_spin(&clock_lock); } while (0)
 #define	RTC_UNLOCK	do { if (!kdb_active) mtx_unlock_spin(&clock_lock); } while (0)
 
-int	atrtcclock_disable = 0;
+#define IO_DELAY()	(void)inb(0x84)
+#define IO_RTC_ADDR	(IO_RTC + 0)
+#define IO_RTC_DATA	(IO_RTC + 1)
 
 static	int	rtc_reg = -1;
 static	u_char	rtc_statusa = RTCSA_DIVIDER | RTCSA_NOPROF;
@@ -73,10 +76,10 @@
 
 	RTC_LOCK;
 	if (rtc_reg != reg) {
-		inb(0x84);
+		IO_DELAY();
 		outb(IO_RTC, reg);
 		rtc_reg = reg;
-		inb(0x84);
+		IO_DELAY();
 	}
 	val = inb(IO_RTC + 1);
 	RTC_UNLOCK;
@@ -89,13 +92,13 @@
 
 	RTC_LOCK;
 	if (rtc_reg != reg) {
-		inb(0x84);
+		IO_DELAY();
 		outb(IO_RTC, reg);
 		rtc_reg = reg;
-		inb(0x84);
+		IO_DELAY();
 	}
 	outb(IO_RTC + 1, val);
-	inb(0x84);
+	IO_DELAY();
 	RTC_UNLOCK;
 }
 
@@ -105,7 +108,7 @@
 	return(bcd2bin(rtcin(port)));
 }
 
-static void
+void
 atrtc_start(void)
 {
 
@@ -155,15 +158,7 @@
  * RTC driver for subr_rtc
  */
 
-struct atrtc_softc {
-	int port_rid, intr_rid;
-	struct resource *port_res;
-	struct resource *intr_res;
-	void *intr_handler;
-	struct eventtimer et;
-};
-
-static int
+int
 rtc_start(struct eventtimer *et, sbintime_t first, sbintime_t period)
 {
 
@@ -172,7 +167,7 @@
 	return (0);
 }
 
-static int
+int
 rtc_stop(struct eventtimer *et)
 {
 
@@ -201,7 +196,7 @@
  * Stat clock ticks can still be lost, causing minor loss of accuracy
  * in the statistics, but the stat clock will no longer stop.
  */
-static int
+int
 rtc_intr(void *arg)
 {
 	struct atrtc_softc *sc = (struct atrtc_softc *)arg;
@@ -215,86 +210,7 @@
 	return(flag ? FILTER_HANDLED : FILTER_STRAY);
 }
 
-/*
- * Attach to the ISA PnP descriptors for the timer and realtime clock.
- */
-static struct isa_pnp_id atrtc_ids[] = {
-	{ 0x000bd041 /* PNP0B00 */, "AT realtime clock" },
-	{ 0 }
-};
-
-static int
-atrtc_probe(device_t dev)
-{
-	int result;
-	
-	result = ISA_PNP_PROBE(device_get_parent(dev), dev, atrtc_ids);
-	/* ENOENT means no PnP-ID, device is hinted. */
-	if (result == ENOENT) {
-		device_set_desc(dev, "AT realtime clock");
-		return (BUS_PROBE_LOW_PRIORITY);
-	}
-	return (result);
-}
-
-static int
-atrtc_attach(device_t dev)
-{
-	struct atrtc_softc *sc;
-	u_long s;
-	int i;
-
-	sc = device_get_softc(dev);
-	sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
-	    IO_RTC, IO_RTC + 1, 2, RF_ACTIVE);
-	if (sc->port_res == NULL)
-		device_printf(dev, "Warning: Couldn't map I/O.\n");
-	atrtc_start();
-	clock_register(dev, 1000000);
-	bzero(&sc->et, sizeof(struct eventtimer));
-	if (!atrtcclock_disable &&
-	    (resource_int_value(device_get_name(dev), device_get_unit(dev),
-	     "clock", &i) != 0 || i != 0)) {
-		sc->intr_rid = 0;
-		while (bus_get_resource(dev, SYS_RES_IRQ, sc->intr_rid,
-		    &s, NULL) == 0 && s != 8)
-			sc->intr_rid++;
-		sc->intr_res = bus_alloc_resource(dev, SYS_RES_IRQ,
-		    &sc->intr_rid, 8, 8, 1, RF_ACTIVE);
-		if (sc->intr_res == NULL) {
-			device_printf(dev, "Can't map interrupt.\n");
-			return (0);
-		} else if ((bus_setup_intr(dev, sc->intr_res, INTR_TYPE_CLK,
-		    rtc_intr, NULL, sc, &sc->intr_handler))) {
-			device_printf(dev, "Can't setup interrupt.\n");
-			return (0);
-		} else { 
-			/* Bind IRQ to BSP to avoid live migration. */
-			bus_bind_intr(dev, sc->intr_res, 0);
-		}
-		sc->et.et_name = "RTC";
-		sc->et.et_flags = ET_FLAGS_PERIODIC | ET_FLAGS_POW2DIV;
-		sc->et.et_quality = 0;
-		sc->et.et_frequency = 32768;
-		sc->et.et_min_period = 0x00080000;
-		sc->et.et_max_period = 0x80000000;
-		sc->et.et_start = rtc_start;
-		sc->et.et_stop = rtc_stop;
-		sc->et.et_priv = dev;
-		et_register(&sc->et);
-	}
-	return(0);
-}
-
-static int
-atrtc_resume(device_t dev)
-{
-
-	atrtc_restore();
-	return(0);
-}
-
-static int
+int
 atrtc_settime(device_t dev __unused, struct timespec *ts)
 {
 	struct clocktime ct;
@@ -322,7 +238,7 @@
 	return (0);
 }
 
-static int
+int
 atrtc_gettime(device_t dev, struct timespec *ts)
 {
 	struct clocktime ct;
@@ -362,34 +278,6 @@
 	return (clock_ct_to_ts(&ct, ts));
 }
 
-static device_method_t atrtc_methods[] = {
-	/* Device interface */
-	DEVMETHOD(device_probe,		atrtc_probe),
-	DEVMETHOD(device_attach,	atrtc_attach),
-	DEVMETHOD(device_detach,	bus_generic_detach),
-	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
-	DEVMETHOD(device_suspend,	bus_generic_suspend),
-		/* XXX stop statclock? */
-	DEVMETHOD(device_resume,	atrtc_resume),
-
-	/* clock interface */
-	DEVMETHOD(clock_gettime,	atrtc_gettime),
-	DEVMETHOD(clock_settime,	atrtc_settime),
-
-	{ 0, 0 }
-};
-
-static driver_t atrtc_driver = {
-	"atrtc",
-	atrtc_methods,
-	sizeof(struct atrtc_softc),
-};
-
-static devclass_t atrtc_devclass;
-
-DRIVER_MODULE(atrtc, isa, atrtc_driver, atrtc_devclass, 0, 0);
-DRIVER_MODULE(atrtc, acpi, atrtc_driver, atrtc_devclass, 0, 0);
-
 #include "opt_ddb.h"
 #ifdef DDB
 #include <ddb/ddb.h>
Index: sys/x86/isa/atrtc_acpi.c
===================================================================
--- sys/x86/isa/atrtc_acpi.c	(revision 0)
+++ sys/x86/isa/atrtc_acpi.c	(working copy)
@@ -0,0 +1,131 @@
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/clock.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <contrib/dev/acpica/include/acpi.h>
+#include <contrib/dev/acpica/include/accommon.h>
+#include <dev/acpica/acpivar.h>
+#include <isa/rtc.h>
+
+#include "atrtc_acpi.h"
+#include "opt_acpi.h"
+
+struct atrtc_acpi_stuff {
+	ACPI_HANDLE acpi_handle;	/* Handle of the PNP0B00 node */
+	int acpi_handle_registered;	/* 0 = acpi_handle not registered */
+};
+
+static void
+acpi_cmos_read(ACPI_PHYSICAL_ADDRESS address, UINT8 *buf, UINT32 buflen)
+{
+	UINT32 offset;
+
+	for (offset = 0; offset < buflen; ++offset) {
+		buf[offset] = rtcin(address + offset) & 0xff;
+	}
+}
+
+static void
+acpi_cmos_write(ACPI_PHYSICAL_ADDRESS address, const UINT8 *buf, UINT32 buflen)
+{
+	UINT32 offset;
+
+	for (offset = 0; offset < buflen; ++offset) {
+		writertc(address + offset, buf[offset]);
+	}
+}
+
+static int
+acpi_check_rtc_access(int is_read, u_long addr, u_long len)
+{
+	int retval = 1;	/* Success */
+
+	if (is_read) {
+		/* Reading 0x0C will muck with interrupts */
+		if (addr + len - 1 >= 0x0C && addr <= 0x0c)
+			retval = 0;
+	} else {
+		/* Allow single-byte writes to alarm registers and
+		 * addr >= 0x30, else deny.
+		 */
+		if (!((len == 1 && (addr <= 5 && (addr & 1))) || addr >= 0x30))
+			retval = 0;
+	}
+	return retval;
+}
+
+static ACPI_STATUS
+acpi_rtc_cmos_handler(UINT32 func, ACPI_PHYSICAL_ADDRESS addr,
+    UINT32 bitwidth, UINT64 *value, void *context, void *region_context)
+{
+	device_t dev;
+	struct atrtc_softc *sc;
+	UINT32 bytewidth = bitwidth >> 3;
+
+	dev = (device_t)context;
+	sc = device_get_softc(dev);
+	if (!value || !sc) {
+		printf("NULL parameter.\n");
+		return AE_BAD_PARAMETER;
+	}
+	if (bitwidth == 0 || bitwidth > 32 || (bitwidth & 0x07) ||
+			addr + bytewidth - 1 > 63) {
+		printf("Invalid bitwidth (%u) or addr (0x%08lx).\n", bitwidth,
+				addr);
+		return AE_BAD_PARAMETER;
+	}
+	if (!acpi_check_rtc_access(func == ACPI_READ, addr, bytewidth)) {
+		printf("Bad CMOS %s access at addr 0x%08lx.\n",
+			func == ACPI_READ ? "read" : "write", addr);
+		return AE_BAD_PARAMETER;
+	}
+
+	switch (func) {
+		case ACPI_READ:
+			acpi_cmos_read(addr, (UINT8 *)value, bytewidth);
+			break;
+		case ACPI_WRITE:
+			acpi_cmos_write(addr, (const UINT8 *)value, bytewidth);
+			break;
+		default:
+			printf("Invalid function: %d.\n", func);
+			return AE_BAD_PARAMETER;
+	}
+	if (bootverbose)
+		printf("%-5s%02u addr=%04lx val=%08x\n",
+			func == ACPI_READ ? "READ" : "WRITE", bytewidth,
+			addr, *((UINT32 *)value));
+	return AE_OK;
+}
+
+static devclass_t atrtc_acpi_devclass;
+static ACPI_HANDLE acpi_handle = NULL;
+
+DRIVER_MODULE(atrtc, acpi, atrtc_driver, atrtc_acpi_devclass, 0, 0);
+
+int atrtc_acpi_register(device_t dev)
+{
+	ACPI_HANDLE acpi_handle = acpi_get_handle(dev);
+	int retval;
+
+	if ((retval = ACPI_FAILURE(AcpiInstallAddressSpaceHandler(acpi_handle,
+					ACPI_ADR_SPACE_CMOS,
+					acpi_rtc_cmos_handler, NULL, dev))))
+	{
+		device_printf(dev, "Warning: Couldn't register ACPI CMOS address space handler.\n");
+	}
+	return retval ? -1 : 0;
+}
+
+int atrtc_acpi_unregister(device_t dev)
+{
+	if (acpi_handle)
+		AcpiRemoveAddressSpaceHandler(acpi_handle,
+				ACPI_ADR_SPACE_CMOS, acpi_rtc_cmos_handler);
+	return 0;
+}

Property changes on: sys/x86/isa/atrtc_acpi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: sys/x86/isa/atrtc_acpi.h
===================================================================
--- sys/x86/isa/atrtc_acpi.h	(revision 0)
+++ sys/x86/isa/atrtc_acpi.h	(working copy)
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ * $FreeBSD$
+ */
+
+
+#ifndef _X86_ISA_ATRTC_ACPI_H_
+#define	_X86_ISA_ATRTC_ACPI_H_
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+
+
+int	atrtc_acpi_register(device_t dev);
+int	atrtc_acpi_unregister(device_t dev);
+
+driver_t atrtc_driver;
+
+#endif /* !_X86_ISA_ATRTC_ACPI_H_ */

Property changes on: sys/x86/isa/atrtc_acpi.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: sys/x86/isa/atrtc_isa.c
===================================================================
--- sys/x86/isa/atrtc_isa.c	(revision 0)
+++ sys/x86/isa/atrtc_isa.c	(working copy)
@@ -0,0 +1,178 @@
+/*-
+ * Copyright (c) 2008 Poul-Henning Kamp
+ * Copyright (c) 2010 Alexander Motin <mav@FreeBSD.org>
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/clock.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/kdb.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/proc.h>
+#include <sys/timeet.h>
+#include <sys/rman.h>
+
+#include <isa/isavar.h>
+#include <isa/isareg.h>
+#include <isa/rtc.h>
+#include <machine/intr_machdep.h>
+#include <machine/resource.h>
+
+#include "clock_if.h"
+#include "atrtcvar.h"
+#include "atrtc_acpi.h"
+
+
+int atrtcclock_disable = 0;
+
+static int atrtc_isa_probe(device_t dev);
+
+/*
+ * Attach to the ISA PnP descriptors for the timer and realtime clock.
+ */
+static struct isa_pnp_id atrtc_ids[] = {
+	{ 0x000bd041 /* PNP0B00 */, "AT realtime clock" },
+	{ 0 }
+};
+
+static int
+atrtc_isa_probe(device_t dev)
+{
+	int result;
+	
+	result = ISA_PNP_PROBE(device_get_parent(dev), dev, atrtc_ids);
+	/* ENOENT means no PnP-ID, device is hinted. */
+	if (result == ENOENT) {
+		device_set_desc(dev, "AT realtime clock");
+		return (BUS_PROBE_LOW_PRIORITY);
+	}
+	return (result);
+}
+
+static int
+atrtc_isa_attach(device_t dev)
+{
+	struct atrtc_softc *sc;
+	u_long s;
+	int i;
+
+	sc = device_get_softc(dev);
+	sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
+	    IO_RTC, IO_RTC + 1, 2, RF_ACTIVE);
+	if (sc->port_res == NULL)
+		device_printf(dev, "Warning: Couldn't map I/O.\n");
+	atrtc_start();
+	clock_register(dev, 1000000);
+	bzero(&sc->et, sizeof(struct eventtimer));
+	if (!atrtcclock_disable &&
+	    (resource_int_value(device_get_name(dev), device_get_unit(dev),
+	     "clock", &i) != 0 || i != 0)) {
+		sc->intr_rid = 0;
+		while (bus_get_resource(dev, SYS_RES_IRQ, sc->intr_rid,
+		    &s, NULL) == 0 && s != 8)
+			sc->intr_rid++;
+		sc->intr_res = bus_alloc_resource(dev, SYS_RES_IRQ,
+		    &sc->intr_rid, 8, 8, 1, RF_ACTIVE);
+		if (sc->intr_res == NULL) {
+			device_printf(dev, "Can't map interrupt.\n");
+			return (0);
+		} else if ((bus_setup_intr(dev, sc->intr_res, INTR_TYPE_CLK,
+		    rtc_intr, NULL, sc, &sc->intr_handler))) {
+			device_printf(dev, "Can't setup interrupt.\n");
+			return (0);
+		} else { 
+			/* Bind IRQ to BSP to avoid live migration. */
+			bus_bind_intr(dev, sc->intr_res, 0);
+		}
+		(void)atrtc_acpi_register(dev);
+		sc->et.et_name = "RTC";
+		sc->et.et_flags = ET_FLAGS_PERIODIC | ET_FLAGS_POW2DIV;
+		sc->et.et_quality = 0;
+		sc->et.et_frequency = 32768;
+		sc->et.et_min_period = 0x00080000;
+		sc->et.et_max_period = 0x80000000;
+		sc->et.et_start = rtc_start;
+		sc->et.et_stop = rtc_stop;
+		sc->et.et_priv = dev;
+		et_register(&sc->et);
+	}
+	return(0);
+}
+
+static int atrtc_isa_detach(device_t dev)
+{
+	struct atrtc_softc *sc;
+
+	sc = device_get_softc(dev);
+	(void)atrtc_acpi_unregister(dev);
+	return bus_generic_detach(dev);
+}
+
+static int
+atrtc_resume(device_t dev)
+{
+
+	atrtc_restore();
+	return(0);
+}
+
+static device_method_t atrtc_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		atrtc_isa_probe),
+	DEVMETHOD(device_attach,	atrtc_isa_attach),
+	DEVMETHOD(device_detach,	atrtc_isa_detach),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
+	DEVMETHOD(device_suspend,	bus_generic_suspend),
+		/* XXX stop statclock? */
+	DEVMETHOD(device_resume,	atrtc_resume),
+
+	/* clock interface */
+	DEVMETHOD(clock_gettime,	atrtc_gettime),
+	DEVMETHOD(clock_settime,	atrtc_settime),
+
+	{ 0, 0 }
+};
+
+driver_t atrtc_driver = {
+	"atrtc",
+	atrtc_methods,
+	sizeof(struct atrtc_softc),
+};
+
+static devclass_t atrtc_isa_devclass;
+
+DRIVER_MODULE(atrtc, isa, atrtc_driver, atrtc_isa_devclass, 0, 0);
+

Property changes on: sys/x86/isa/atrtc_isa.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: sys/x86/isa/atrtcvar.h
===================================================================
--- sys/x86/isa/atrtcvar.h	(revision 0)
+++ sys/x86/isa/atrtcvar.h	(working copy)
@@ -0,0 +1,23 @@
+#ifndef ATRTCVAR_H
+#define ATRTCVAR_H
+
+#include <sys/types.h>
+#include <sys/timeet.h>
+
+struct atrtc_softc {
+	int port_rid, intr_rid;
+	struct resource *port_res;
+	struct resource *intr_res;
+	void *intr_handler;
+	struct eventtimer et;
+};
+
+int atrtc_gettime(device_t dev, struct timespec *ts);
+int atrtc_settime(device_t dev __unused, struct timespec *ts);
+void atrtc_start(void);
+void atrtc_restore(void);
+int rtc_start(struct eventtimer *et, sbintime_t first, sbintime_t period);
+int rtc_stop(struct eventtimer *et);
+int rtc_intr(void *arg);
+
+#endif	/* ATRTCVAR_H */

Property changes on: sys/x86/isa/atrtcvar.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property

--------------050805090500090807050701--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?558CA7C9.9000304>