-/* $OpenBSD: prtc.c,v 1.3 2014/05/10 12:36:22 kettenis Exp $ */
+/* $OpenBSD: prtc.c,v 1.4 2018/08/28 00:00:42 dlg Exp $ */
/*
* Copyright (c) 2008 Mark Kettenis
int prtc_gettime(todr_chip_handle_t, struct timeval *);
int prtc_settime(todr_chip_handle_t, struct timeval *);
+int prtc_opl_gettime(todr_chip_handle_t, struct timeval *);
+int prtc_opl_settime(todr_chip_handle_t, struct timeval *);
+
int
prtc_match(struct device *parent, void *match, void *aux)
{
prtc_attach(struct device *parent, struct device *self, void *aux)
{
todr_chip_handle_t handle;
+ char buf[32];
+ int opl;
+
+ opl = OF_getprop(findroot(), "name", buf, sizeof(buf)) > 0 &&
+ strcmp(buf, "SUNW,SPARC-Enterprise") == 0;
+
+ if (opl)
+ printf(": OPL");
printf("\n");
panic("couldn't allocate todr_handle");
handle->cookie = self;
- handle->todr_gettime = prtc_gettime;
- handle->todr_settime = prtc_settime;
+ if (opl) {
+ handle->todr_gettime = prtc_opl_gettime;
+ handle->todr_settime = prtc_opl_settime;
+ } else {
+ handle->todr_gettime = prtc_gettime;
+ handle->todr_settime = prtc_settime;
+ }
handle->bus_cookie = NULL;
handle->todr_setwen = NULL;
+
todr_handle = handle;
}
int
prtc_gettime(todr_chip_handle_t handle, struct timeval *tv)
{
- u_int32_t tod = 0;
char buf[32];
-
- if (OF_getprop(findroot(), "name", buf, sizeof(buf)) > 0 &&
- strcmp(buf, "SUNW,SPARC-Enterprise") == 0) {
- tv->tv_sec = prom_opl_get_tod();
- tv->tv_usec = 0;
- return (0);
- }
+ u_int32_t tod = 0;
snprintf(buf, sizeof(buf), "h# %08lx unix-gettod", (long)&tod);
OF_interpret(buf, 0);
prtc_settime(todr_chip_handle_t handle, struct timeval *tv)
{
return (0);
-}
+}
+
+int
+prtc_opl_gettime(todr_chip_handle_t handle, struct timeval *tv)
+{
+ struct {
+ cell_t name;
+ cell_t nargs;
+ cell_t nrets;
+ cell_t stick;
+ cell_t time;
+ } args = {
+ .name = ADR2CELL("FJSV,get-tod"),
+ .nargs = 0,
+ .nrets = 2,
+ };
+
+ if (openfirmware(&args) == -1)
+ return (-1);
+
+ tv->tv_sec = args.time;
+ tv->tv_usec = 0;
+
+ return (0);
+}
+
+int
+prtc_opl_settime(todr_chip_handle_t handle, struct timeval *tv)
+{
+ struct timeval otv;
+ struct {
+ cell_t name;
+ cell_t nargs;
+ cell_t nrets;
+ cell_t diff;
+ } args = {
+ .name = ADR2CELL("FJSV,set-domain-time"),
+ .nargs = 1,
+ .nrets = 0,
+ };
+
+ if (prtc_opl_gettime(handle, &otv) == -1)
+ return (-1);
+
+ args.diff = tv->tv_sec - otv.tv_sec;
+ if (args.diff == 0)
+ return (0);
+
+ if (openfirmware(&args) == -1)
+ return (-1);
+
+ return (0);
+}
-/* $OpenBSD: sparc64.h,v 1.13 2008/12/30 00:54:24 kettenis Exp $ */
+/* $OpenBSD: sparc64.h,v 1.14 2018/08/28 00:00:42 dlg Exp $ */
/* $NetBSD: sparc64.h,v 1.3 2000/10/20 05:47:03 mrg Exp $ */
/*
void prom_start_cpu(int cpu, void *func, long arg);
void prom_start_cpu_by_cpuid(int cpu, void *func, long arg);
const char *prom_serengeti_set_console_input(const char *);
-time_t prom_opl_get_tod(void);
uint64_t prom_set_sun4v_api_version(uint64_t, uint64_t, uint64_t, uint64_t *);
void prom_sun4v_soft_state_supported(void);
-/* $OpenBSD: ofw_machdep.c,v 1.33 2016/03/07 13:21:51 naddy Exp $ */
+/* $OpenBSD: ofw_machdep.c,v 1.34 2018/08/28 00:00:42 dlg Exp $ */
/* $NetBSD: ofw_machdep.c,v 1.16 2001/07/20 00:07:14 eeh Exp $ */
/*
return (const char *)args.old;
}
-time_t
-prom_opl_get_tod(void)
-{
- static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t stick;
- cell_t time;
- } args;
-
- args.name = ADR2CELL("FJSV,get-tod");
- args.nargs = 0;
- args.nreturns = 2;
-
- if (openfirmware(&args) == -1)
- return (time_t)-1;
-
- return (time_t)args.time;
-}
-
uint64_t
prom_set_sun4v_api_version(uint64_t api_group, uint64_t major,
uint64_t minor, uint64_t *supported_minor)