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

Modified Files:
        src/sys/arch/alpha/conf: files.alpha
        src/sys/arch/alpha/gbus: gbus.c gbusvar.h
Added Files:
        src/sys/arch/alpha/gbus: gbus_io.c

Log Message:
Add a bus space implementation for the Gbus, the general 8-bit bus present
on Laser / TurboLaser CPU modules.


To generate a diff of this commit:
cvs rdiff -u -r1.196 -r1.197 src/sys/arch/alpha/conf/files.alpha
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/alpha/gbus/gbus.c \
    src/sys/arch/alpha/gbus/gbusvar.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/alpha/gbus/gbus_io.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/conf/files.alpha
diff -u src/sys/arch/alpha/conf/files.alpha:1.196 src/sys/arch/alpha/conf/files.alpha:1.197
--- src/sys/arch/alpha/conf/files.alpha:1.196	Sat Mar  2 20:15:33 2024
+++ src/sys/arch/alpha/conf/files.alpha	Wed Mar  6 05:33:09 2024
@@ -1,4 +1,4 @@
-# $NetBSD: files.alpha,v 1.196 2024/03/02 20:15:33 thorpej Exp $
+# $NetBSD: files.alpha,v 1.197 2024/03/06 05:33:09 thorpej Exp $
 #
 # alpha-specific configuration info
 
@@ -104,6 +104,7 @@ file	arch/alpha/tlsb/tlsbmem.c	tlsbmem
 device	gbus { offset = -1 }
 attach	gbus at tlsb
 file	arch/alpha/gbus/gbus.c		gbus
+file	arch/alpha/gbus/gbus_io.c	gbus
 
 #
 # MCBUS support

Index: src/sys/arch/alpha/gbus/gbus.c
diff -u src/sys/arch/alpha/gbus/gbus.c:1.1 src/sys/arch/alpha/gbus/gbus.c:1.2
--- src/sys/arch/alpha/gbus/gbus.c:1.1	Sat Mar  2 19:57:57 2024
+++ src/sys/arch/alpha/gbus/gbus.c	Wed Mar  6 05:33:09 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: gbus.c,v 1.1 2024/03/02 19:57:57 thorpej Exp $ */
+/* $NetBSD: gbus.c,v 1.2 2024/03/06 05:33:09 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 by Matthew Jacob
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: gbus.c,v 1.1 2024/03/02 19:57:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gbus.c,v 1.2 2024/03/06 05:33:09 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -70,10 +70,10 @@ CFATTACH_DECL_NEW(gbus, sizeof(struct gb
 static int	gbusprint(void *, const char *);
 
 static const struct gbus_attach_args gbus_children[] = {
-	{ "zsc",	GBUS_DUART0_OFFSET },
-	{ "zsc",	GBUS_DUART1_OFFSET },
-	{ "mcclock",	GBUS_CLOCK_OFFSET },
-	{ NULL,		0 },
+	{ "zsc",	NULL,	GBUS_DUART0_OFFSET },
+	{ "zsc",	NULL,	GBUS_DUART1_OFFSET },
+	{ "mcclock",	NULL,	GBUS_CLOCK_OFFSET },
+	{ NULL,		NULL,	0 },
 };
 
 static int
@@ -113,6 +113,7 @@ gbusattach(device_t parent, device_t sel
 	struct gbus_softc *sc = device_private(self);
 	struct tlsb_dev_attach_args *ta = aux;
 	const struct gbus_attach_args *ga;
+	bus_space_tag_t iot = gbus_io_init(TLSB_GBUS_BASE);
 	int locs[GBUSCF_NLOCS];
 
 	aprint_normal("\n");
@@ -123,6 +124,7 @@ gbusattach(device_t parent, device_t sel
 	/* Attach the children. */
 	for (ga = gbus_children; ga->ga_name != NULL; ga++) {
 		struct gbus_attach_args gaa = *ga;
+		gaa.ga_iot = iot;
 		locs[GBUSCF_OFFSET] = gaa.ga_offset;
 		config_found(self, &gaa, gbusprint,
 		    CFARGS(.submatch = config_stdsubmatch,
Index: src/sys/arch/alpha/gbus/gbusvar.h
diff -u src/sys/arch/alpha/gbus/gbusvar.h:1.1 src/sys/arch/alpha/gbus/gbusvar.h:1.2
--- src/sys/arch/alpha/gbus/gbusvar.h:1.1	Sat Mar  2 19:57:57 2024
+++ src/sys/arch/alpha/gbus/gbusvar.h	Wed Mar  6 05:33:09 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: gbusvar.h,v 1.1 2024/03/02 19:57:57 thorpej Exp $ */
+/* $NetBSD: gbusvar.h,v 1.2 2024/03/06 05:33:09 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,6 +30,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef _ALPHA_GBUS_GBUSVAR_H_
+#define	_ALPHA_GBUS_GBUSVAR_H_
+
 /*
  * Autoconfiguration definitions for the Gbus found on TurboLaser CPU modules.
  */
@@ -37,6 +40,11 @@
 #include <sys/bus.h>
 
 struct gbus_attach_args {
-	const char *ga_name;		/* name of device */
-	bus_addr_t  ga_offset;		/* offset from Gbus base */
+	const char *	ga_name;	/* name of device */
+	bus_space_tag_t	ga_iot;		/* I/O space tag */
+	bus_addr_t	ga_offset;	/* offset from Gbus base */
 };
+
+bus_space_tag_t	gbus_io_init(paddr_t);
+
+#endif /* _ALPHA_GBUS_GBUSVAR_H_ */

Added files:

Index: src/sys/arch/alpha/gbus/gbus_io.c
diff -u /dev/null src/sys/arch/alpha/gbus/gbus_io.c:1.1
--- /dev/null	Wed Mar  6 05:33:10 2024
+++ src/sys/arch/alpha/gbus/gbus_io.c	Wed Mar  6 05:33:09 2024
@@ -0,0 +1,177 @@
+/* $NetBSD: gbus_io.c,v 1.1 2024/03/06 05:33:09 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2024 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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.
+ */
+
+/*
+ * Bus space implementation for the Gbus: a general 8-bit bus found
+ * on Laser / TurboLaser CPU modules.
+ */
+
+#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
+
+__KERNEL_RCSID(0, "$NetBSD: gbus_io.c,v 1.1 2024/03/06 05:33:09 thorpej Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/endian.h>
+#include <sys/vmem.h>
+
+#include <sys/bus.h>
+
+#include <alpha/gbus/gbusvar.h>
+
+/*
+ * While physically there is one Gbus per CPU module on the system,
+ * logically there is only one (the one on the CPU module that holds
+ * the primary CPU), and this describes it.
+ */
+static struct gbus_config {
+	paddr_t		gc_sysbase;	/* system base address of Gbus */
+	struct alpha_bus_space gc_st;	/* the Gbus's space tag */
+} gbus_config;
+
+/* Adjacent bytes on the Gbus are spaced 64 bytes apart. */
+#define	GBUS_ADDR_SHIFT		6
+
+static int
+gbus_io_map(
+	void *v,
+	bus_addr_t addr,
+	bus_size_t size			__unused,
+	int flags			__unused,
+	bus_space_handle_t *iohp,
+	int acct			__unused)
+{
+	struct gbus_config * const gc = v;
+
+	*iohp = ALPHA_PHYS_TO_K0SEG(gc->gc_sysbase + addr);
+
+	return 0;
+}
+
+static void
+gbus_io_unmap(
+	void *v				__unused,
+	bus_space_handle_t ioh		__unused,
+	bus_size_t size			__unused,
+	int acct			__unused)
+{
+	/* No work to do. */
+}
+
+static void
+gbus_io_barrier(
+	void *v				__unused,
+	bus_space_handle_t ioh		__unused,
+	bus_size_t off			__unused,
+	bus_size_t len			__unused,
+	int flags			__unused)
+{
+	if (flags & BUS_SPACE_BARRIER_READ) {
+		alpha_mb();
+	} else if (flags & BUS_SPACE_BARRIER_WRITE) {
+		alpha_wmb();
+	}
+}
+
+__CTASSERT(_BYTE_ORDER == _LITTLE_ENDIAN);
+
+/*
+ * A 32-bit pointer is used here because the bus transaction is going to
+ * be 32-bit regardless, and this avoids having the compiler generate
+ * extbl / insbl / mskbl unnecessarily (or r/m/w in the write case).
+ */
+#define	GBUS_ADDR(ioh, off)						\
+	(uint32_t *)((ioh) + ((off) << GBUS_ADDR_SHIFT))
+
+static uint8_t
+gbus_io_read_1(
+	void *v				__unused,
+	bus_space_handle_t ioh,
+	bus_size_t off)
+{
+	uint32_t *addr = GBUS_ADDR(ioh, off);
+
+	alpha_mb();
+	return (uint8_t)atomic_load_relaxed(addr);
+}
+
+static void
+gbus_io_write_1(
+	void *v				__unused,
+	bus_space_handle_t ioh,
+	bus_size_t off,
+	uint8_t val)
+{
+	uint32_t *addr = GBUS_ADDR(ioh, off);
+
+	atomic_store_relaxed(addr, (uint32_t)val);
+	alpha_mb();
+}
+
+bus_space_tag_t
+gbus_io_init(paddr_t sysbase)
+{
+	struct gbus_config * const gc = &gbus_config;
+	bus_space_tag_t t = &gc->gc_st;
+
+	if (t->abs_cookie == gc) {
+		/* Already initialized. */
+		KASSERT(gc->gc_sysbase == sysbase);
+		return t;
+	}
+
+	gc->gc_sysbase = sysbase;
+	memset(t, 0, sizeof(*t));
+
+	/*
+	 * Initialize the bus space tag.  We just support the bare
+	 * minimum operations required by Gbus devices.
+	 */
+
+	/* cookie */
+	t->abs_cookie =		gc;
+
+	/* mapping/unmapping */
+	t->abs_map =		gbus_io_map;
+	t->abs_unmap =		gbus_io_unmap;
+
+	/* barrier */
+	t->abs_barrier =	gbus_io_barrier;
+
+	/* read (single) */
+	t->abs_r_1 =		gbus_io_read_1;
+
+	/* write (single) */
+	t->abs_w_1 =		gbus_io_write_1;
+
+	return t;
+}

Reply via email to