Module Name:    src
Committed By:   thorpej
Date:           Wed Mar  6 05:44:44 UTC 2024

Modified Files:
        src/sys/arch/alpha/gbus: mcclock_gbus.c

Log Message:
bus_space-ify.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/alpha/gbus/mcclock_gbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/gbus/mcclock_gbus.c
diff -u src/sys/arch/alpha/gbus/mcclock_gbus.c:1.2 src/sys/arch/alpha/gbus/mcclock_gbus.c:1.3
--- src/sys/arch/alpha/gbus/mcclock_gbus.c:1.2	Sat Mar  2 22:58:29 2024
+++ src/sys/arch/alpha/gbus/mcclock_gbus.c	Wed Mar  6 05:44:44 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: mcclock_gbus.c,v 1.2 2024/03/02 22:58:29 thorpej Exp $ */
+/* $NetBSD: mcclock_gbus.c,v 1.3 2024/03/06 05:44:44 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 by Matthew Jacob
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: mcclock_gbus.c,v 1.2 2024/03/02 22:58:29 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcclock_gbus.c,v 1.3 2024/03/06 05:44:44 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -43,8 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: mcclock_gbus
 
 #include <alpha/gbus/gbusvar.h>
 
-#include <alpha/tlsb/tlsbreg.h>		/* XXX */
-
 #include <dev/clock_subr.h>
 
 #include <dev/ic/mc146818reg.h>
@@ -54,27 +52,15 @@ __KERNEL_RCSID(0, "$NetBSD: mcclock_gbus
 
 #include "ioconf.h"
 
-#define	KV(_addr)	((void *)ALPHA_PHYS_TO_K0SEG((_addr)))
-/*
- * Registers are 64 bytes apart (and 1 byte wide)
- */
-#define	REGSHIFT	6
-
-struct mcclock_gbus_softc {
-	struct mc146818_softc	sc_mc146818;
-	unsigned long regbase;
-};
-
 static int	mcclock_gbus_match(device_t, cfdata_t, void *);
 static void	mcclock_gbus_attach(device_t, device_t, void *);
 
-CFATTACH_DECL_NEW(mcclock_gbus, sizeof(struct mcclock_gbus_softc),
+CFATTACH_DECL_NEW(mcclock_gbus, sizeof(struct mc146818_softc),
     mcclock_gbus_match, mcclock_gbus_attach, NULL, NULL);
 
 static void	mcclock_gbus_write(struct mc146818_softc *, u_int, u_int);
 static u_int	mcclock_gbus_read(struct mc146818_softc *, u_int);
 
-
 static int
 mcclock_gbus_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -88,14 +74,17 @@ mcclock_gbus_match(device_t parent, cfda
 static void
 mcclock_gbus_attach(device_t parent, device_t self, void *aux)
 {
-	struct mcclock_gbus_softc *tsc = device_private(self);
+	struct mc146818_softc *sc = device_private(self);
 	struct gbus_attach_args *ga = aux;
-	struct mc146818_softc *sc = &tsc->sc_mc146818;
-
-	/* XXX Should be bus.h'd, so we can accommodate the kn7aa. */
-	tsc->regbase = TLSB_GBUS_BASE + ga->ga_offset;
 
 	sc->sc_dev = self;
+	sc->sc_bst = ga->ga_iot;
+
+	if (bus_space_map(sc->sc_bst, ga->ga_offset, MC_NREGS+MC_NVRAM_SIZE,
+			  0, &sc->sc_bsh) != 0) {
+		panic("mcclock_gbus_attach: couldn't map clock I/O space");
+	}
+
 	sc->sc_mcread  = mcclock_gbus_read;
 	sc->sc_mcwrite = mcclock_gbus_write;
 
@@ -105,19 +94,11 @@ mcclock_gbus_attach(device_t parent, dev
 static void
 mcclock_gbus_write(struct mc146818_softc *sc, u_int reg, u_int val)
 {
-	struct mcclock_gbus_softc *tsc = (void *)sc;
-	unsigned char *ptr = (unsigned char *)
-		KV(tsc->regbase + (reg << REGSHIFT));
-
-	*ptr = val;
+	bus_space_write_1(sc->sc_bst, sc->sc_bsh, reg, (uint8_t)val);
 }
 
 static u_int
 mcclock_gbus_read(struct mc146818_softc *sc, u_int reg)
 {
-	struct mcclock_gbus_softc *tsc = (void *)sc;
-	unsigned char *ptr = (unsigned char *)
-		KV(tsc->regbase + (reg << REGSHIFT));
-
-	return *ptr;
+	return bus_space_read_1(sc->sc_bst, sc->sc_bsh, reg);
 }

Reply via email to