Add time-of-day support to sun4v

This commit is contained in:
kmacy 2006-11-13 01:02:18 +00:00
parent 341ae2b09b
commit 1ad3f70985
2 changed files with 41 additions and 125 deletions

View File

@ -80,6 +80,7 @@ sun4v/sun4v/ofw_machdep.c standard
sun4v/sun4v/pmap.c standard
sun4v/sun4v/prof_machdep.c optional profiling-routine
sun4v/sun4v/rwindow.c standard
sun4v/sun4v/rtc.c standard
sun4v/sun4v/simdisk.c optional simulator
sun4v/sun4v/support.S standard
sun4v/sun4v/sys_machdep.c standard

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2004 Marius Strobl <marius@FreeBSD.org>
* Copyright (c) 2006 Kip Macy <kmacy@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -27,165 +27,80 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* The `rtc' device is a MC146818 compatible clock found on the ISA bus
* and EBus. The EBus version also has an interrupt property so it could
* be used to drive the statclock etc.
*/
#include "opt_isa.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/clock.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/resource.h>
#include <dev/ofw/ofw_bus.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
#include <isa/isavar.h>
#include <dev/mc146818/mc146818var.h>
#include <machine/hypervisor_api.h>
#include <machine/mdesc_bus.h>
#include <machine/cddl/mdesc.h>
#include <machine/cddl/mdesc_impl.h>
#include "clock_if.h"
static devclass_t rtc_devclass;
static int hv_rtc_attach(device_t dev);
static int hv_rtc_probe(device_t dev);
static int hv_settime(device_t dev, struct timespec *ts);
static int hv_gettime(device_t dev, struct timespec *ts);
static int rtc_attach(device_t dev);
static int rtc_ebus_probe(device_t dev);
#ifdef DEV_ISA
static int rtc_isa_probe(device_t dev);
#endif
static device_method_t rtc_ebus_methods[] = {
static device_method_t hv_rtc_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, rtc_ebus_probe),
DEVMETHOD(device_attach, rtc_attach),
DEVMETHOD(device_probe, hv_rtc_probe),
DEVMETHOD(device_attach, hv_rtc_attach),
/* clock interface */
DEVMETHOD(clock_gettime, mc146818_gettime),
DEVMETHOD(clock_settime, mc146818_settime),
DEVMETHOD(clock_gettime, hv_gettime),
DEVMETHOD(clock_settime, hv_settime),
{ 0, 0 }
};
static driver_t rtc_ebus_driver = {
"rtc",
rtc_ebus_methods,
sizeof(struct mc146818_softc),
static driver_t hv_rtc_driver = {
"hv_rtc",
hv_rtc_methods,
0
};
DRIVER_MODULE(rtc, ebus, rtc_ebus_driver, rtc_devclass, 0, 0);
#ifdef DEV_ISA
static device_method_t rtc_isa_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, rtc_isa_probe),
DEVMETHOD(device_attach, rtc_attach),
/* clock interface */
DEVMETHOD(clock_gettime, mc146818_gettime),
DEVMETHOD(clock_settime, mc146818_settime),
{ 0, 0 }
};
static driver_t rtc_isa_driver = {
"rtc",
rtc_isa_methods,
sizeof(struct mc146818_softc),
};
DRIVER_MODULE(rtc, isa, rtc_isa_driver, rtc_devclass, 0, 0);
#endif
static devclass_t hv_rtc_devclass;
DRIVER_MODULE(rtc, vnex, hv_rtc_driver, hv_rtc_devclass, 0, 0);
static int
rtc_ebus_probe(device_t dev)
hv_rtc_probe(device_t dev)
{
if (strcmp(ofw_bus_get_name(dev), "rtc") == 0) {
device_set_desc(dev, "Real Time Clock");
if (strcmp(mdesc_bus_get_name(dev), "rtc") == 0) {
return (0);
}
return (ENXIO);
}
#ifdef DEV_ISA
static struct isa_pnp_id rtc_isa_ids[] = {
{ 0x000bd041, "AT realtime clock" }, /* PNP0B00 */
{ 0 }
};
static int
rtc_isa_probe(device_t dev)
hv_rtc_attach(device_t dev)
{
if (ISA_PNP_PROBE(device_get_parent(dev), dev, rtc_isa_ids) == 0) {
device_set_desc(dev, "Real Time Clock");
return (0);
}
return (ENXIO);
}
#endif
static int
rtc_attach(device_t dev)
{
struct timespec ts;
struct mc146818_softc *sc;
struct resource *res;
int error, rid, rtype;
sc = device_get_softc(dev);
mtx_init(&sc->sc_mtx, "rtc_mtx", NULL, MTX_SPIN);
if (strcmp(device_get_name(device_get_parent(dev)), "isa") == 0)
rtype = SYS_RES_IOPORT;
else
rtype = SYS_RES_MEMORY;
rid = 0;
res = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE);
if (res == NULL) {
device_printf(dev, "cannot allocate resources\n");
error = ENXIO;
goto fail_mtx;
}
sc->sc_bst = rman_get_bustag(res);
sc->sc_bsh = rman_get_bushandle(res);
/* The TOD clock year 0 is 0. */
sc->sc_year0 = 0;
/* Use default register read/write and century get/set functions. */
sc->sc_flag = MC146818_NO_CENT_ADJUST;
if ((error = mc146818_attach(dev)) != 0) {
device_printf(dev, "cannot attach time of day clock\n");
goto fail_res;
}
if (bootverbose) {
mc146818_gettime(dev, &ts);
device_printf(dev, "current time: %ld.%09ld\n", (long)ts.tv_sec,
ts.tv_nsec);
}
clock_register(dev, 1000000);
return (0);
}
static int
hv_settime(device_t dev, struct timespec *ts)
{
hv_tod_set(ts->tv_sec);
return (0);
}
static int
hv_gettime(device_t dev, struct timespec *ts)
{
ts->tv_nsec = 0;
hv_tod_get(&ts->tv_sec);
return (0);
fail_res:
bus_release_resource(dev, rtype, rid, res);
fail_mtx:
mtx_destroy(&sc->sc_mtx);
return (error);
}