Module Name: src
Committed By: tsutsui
Date: Sun Jul 3 16:03:08 UTC 2022
Modified Files:
src/sys/arch/atari/atari: atari_init.c bus.c machdep.c
src/sys/arch/atari/include: bus_funcs.h
Log Message:
Move the iomem extent stuff managed by bus_space(9) and make them static.
Inspired by MD bus_space(9) implemantation of arc.
Briefly tested on TT030.
To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/atari/atari/atari_init.c
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/atari/atari/bus.c
cvs rdiff -u -r1.187 -r1.188 src/sys/arch/atari/atari/machdep.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/atari/include/bus_funcs.h
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/atari/atari/atari_init.c
diff -u src/sys/arch/atari/atari/atari_init.c:1.105 src/sys/arch/atari/atari/atari_init.c:1.106
--- src/sys/arch/atari/atari/atari_init.c:1.105 Sat Jun 25 13:17:04 2022
+++ src/sys/arch/atari/atari/atari_init.c Sun Jul 3 16:03:08 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: atari_init.c,v 1.105 2022/06/25 13:17:04 tsutsui Exp $ */
+/* $NetBSD: atari_init.c,v 1.106 2022/07/03 16:03:08 tsutsui Exp $ */
/*
* Copyright (c) 1995 Leo Weppelman
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atari_init.c,v 1.105 2022/06/25 13:17:04 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atari_init.c,v 1.106 2022/07/03 16:03:08 tsutsui Exp $");
#include "opt_ddb.h"
#include "opt_mbtype.h"
@@ -58,6 +58,7 @@ __KERNEL_RCSID(0, "$NetBSD: atari_init.c
#include <sys/exec_aout.h>
#include <sys/core.h>
#include <sys/kcore.h>
+#include <sys/bus.h>
#include <uvm/uvm_extern.h>
@@ -110,21 +111,6 @@ static u_int milan_probe_bank(paddr_t pa
#endif
/*
- * Extent maps to manage all memory space, including I/O ranges. Allocate
- * storage for 16 regions in each, initially. Later, iomem_malloc_safe
- * will indicate that it's safe to use malloc() to dynamically allocate
- * region descriptors.
- * This means that the fixed static storage is only used for registrating
- * the found memory regions and the bus-mapping of the console.
- *
- * The extent maps are not static! They are used for bus address space
- * allocation.
- */
-static long iomem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(16) / sizeof(long)];
-struct extent *iomem_ex;
-int iomem_malloc_safe;
-
-/*
* All info needed to generate a panic dump. All fields are setup by
* start_c().
* XXX: Should sheck usage of phys_segs. There is some unwanted overlap
@@ -685,25 +671,13 @@ start_c(int id, u_int ttphystart, u_int
init_stmem();
/*
- * Initialize the I/O mem extent map.
- * Note: we don't have to check the return value since
- * creation of a fixed extent map will never fail (since
- * descriptor storage has already been allocated).
- *
- * N.B. The iomem extent manages _all_ physical addresses
- * on the machine. When the amount of RAM is found, all
- * extents of RAM are allocated from the map.
- */
- iomem_ex = extent_create("iomem", 0x0, 0xffffffff,
- (void *)iomem_ex_storage, sizeof(iomem_ex_storage),
- EX_NOCOALESCE|EX_NOWAIT);
-
- /*
- * Allocate the physical RAM from the extent map
+ * Initialize the iomem extent for bus_space(9) to manage address
+ * spaces and allocate the physical RAM from the extent map.
*/
+ atari_bus_space_extent_init(0x0, 0xffffffff);
for (i = 0; i < NMEM_SEGS && boot_segs[i].end != 0; i++) {
- if (extent_alloc_region(iomem_ex, boot_segs[i].start,
- boot_segs[i].end - boot_segs[i].start, EX_NOWAIT)) {
+ if (atari_bus_space_alloc_physmem(boot_segs[i].start,
+ boot_segs[i].end)) {
/* XXX: Ahum, should not happen ;-) */
printf("Warning: Cannot allocate boot memory from"
" extent map!?\n");
@@ -973,7 +947,6 @@ map_io_areas(paddr_t ptpa, psize_t ptsiz
/* ptsize: Size of 'pt' in bytes */
/* ptextra: #of additional I/O pte's */
{
- extern void bootm_init(vaddr_t, pt_entry_t *, u_long);
vaddr_t ioaddr;
pt_entry_t *pt, *pg, *epg;
pt_entry_t pg_proto;
Index: src/sys/arch/atari/atari/bus.c
diff -u src/sys/arch/atari/atari/bus.c:1.62 src/sys/arch/atari/atari/bus.c:1.63
--- src/sys/arch/atari/atari/bus.c:1.62 Tue May 24 19:55:10 2022
+++ src/sys/arch/atari/atari/bus.c Sun Jul 3 16:03:08 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: bus.c,v 1.62 2022/05/24 19:55:10 andvar Exp $ */
+/* $NetBSD: bus.c,v 1.63 2022/07/03 16:03:08 tsutsui Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#include "opt_m68k_arch.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.62 2022/05/24 19:55:10 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.63 2022/07/03 16:03:08 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -49,6 +49,18 @@ __KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.62
#define _ATARI_BUS_DMA_PRIVATE
#include <sys/bus.h>
+/*
+ * Extent maps to manage all memory space, including I/O ranges. Allocate
+ * storage for 16 regions in each, initially. Later, iomem_malloc_safe
+ * will indicate that it's safe to use malloc() to dynamically allocate
+ * region descriptors.
+ * This means that the fixed static storage is only used for registrating
+ * the found memory regions and the bus-mapping of the console.
+ */
+static long iomem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(16) / sizeof(long)];
+static struct extent *iomem_ex;
+static int iomem_malloc_safe = 0;
+
int bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
bus_size_t alignment, bus_size_t boundary,
bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
@@ -59,9 +71,6 @@ static int _bus_dmamap_load_buffer(bus_
static int bus_mem_add_mapping(bus_space_tag_t t, bus_addr_t bpa,
bus_size_t size, int flags, bus_space_handle_t *bsph);
-extern struct extent *iomem_ex;
-extern int iomem_malloc_safe;
-
extern paddr_t avail_end;
/*
@@ -79,17 +88,16 @@ static long bootm_ex_storage[EXTENT_FIX
sizeof(long)];
static struct extent *bootm_ex;
-void bootm_init(vaddr_t, pt_entry_t *, u_long);
static vaddr_t bootm_alloc(paddr_t pa, u_long size, int flags);
static int bootm_free(vaddr_t va, u_long size);
void
-bootm_init(vaddr_t va, pt_entry_t *ptep, u_long size)
+bootm_init(vaddr_t va, void *ptep, vsize_t size)
{
bootm_ex = extent_create("bootmem", va, va + size,
(void *)bootm_ex_storage, sizeof(bootm_ex_storage),
EX_NOCOALESCE|EX_NOWAIT);
- bootm_ptep = ptep;
+ bootm_ptep = (pt_entry_t *)ptep;
}
vaddr_t
@@ -137,6 +145,47 @@ bootm_free(vaddr_t va, u_long size)
return 1;
}
+void
+atari_bus_space_extent_init(paddr_t startpa, paddr_t endpa)
+{
+
+ /*
+ * Initialize the I/O mem extent map.
+ * Note: we don't have to check the return value since
+ * creation of a fixed extent map will never fail (since
+ * descriptor storage has already been allocated).
+ *
+ * N.B. The iomem extent manages _all_ physical addresses
+ * on the machine. When the amount of RAM is found, all
+ * extents of RAM are allocated from the map.
+ */
+ iomem_ex = extent_create("iomem", startpa, endpa,
+ (void *)iomem_ex_storage, sizeof(iomem_ex_storage),
+ EX_NOCOALESCE | EX_NOWAIT);
+}
+
+int
+atari_bus_space_alloc_physmem(paddr_t startpa, paddr_t endpa)
+{
+
+ return extent_alloc_region(iomem_ex, startpa, endpa - startpa,
+ EX_NOWAIT);
+}
+
+void
+atari_bus_space_malloc_set_safe(void)
+{
+
+ iomem_malloc_safe = EX_MALLOCOK;
+}
+
+int
+atari_bus_space_extent_malloc_flag(void)
+{
+
+ return iomem_malloc_safe;
+}
+
int
bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size, int flags,
bus_space_handle_t *mhp)
@@ -148,15 +197,15 @@ bus_space_map(bus_space_tag_t t, bus_add
* region is available.
*/
error = extent_alloc_region(iomem_ex, bpa + t->base, size,
- EX_NOWAIT | (iomem_malloc_safe ? EX_MALLOCOK : 0));
+ EX_NOWAIT | iomem_malloc_safe);
if (error)
return error;
error = bus_mem_add_mapping(t, bpa, size, flags, mhp);
if (error) {
- if (extent_free(iomem_ex, bpa + t->base, size, EX_NOWAIT |
- (iomem_malloc_safe ? EX_MALLOCOK : 0))) {
+ if (extent_free(iomem_ex, bpa + t->base, size,
+ EX_NOWAIT | iomem_malloc_safe)) {
printf("bus_space_map: pa 0x%lx, size 0x%lx\n",
bpa, size);
printf("bus_space_map: can't free region\n");
@@ -189,8 +238,7 @@ bus_space_alloc(bus_space_tag_t t, bus_a
*/
error = extent_alloc_subregion(iomem_ex, rstart + t->base,
rend + t->base, size, alignment, boundary,
- EX_FAST | EX_NOWAIT | (iomem_malloc_safe ? EX_MALLOCOK : 0),
- &bpa);
+ EX_FAST | EX_NOWAIT | iomem_malloc_safe, &bpa);
if (error)
return error;
@@ -200,8 +248,8 @@ bus_space_alloc(bus_space_tag_t t, bus_a
*/
error = bus_mem_add_mapping(t, bpa, size, flags, bshp);
if (error) {
- if (extent_free(iomem_ex, bpa, size, EX_NOWAIT |
- (iomem_malloc_safe ? EX_MALLOCOK : 0))) {
+ if (extent_free(iomem_ex, bpa, size,
+ EX_NOWAIT | iomem_malloc_safe)) {
printf("bus_space_alloc: pa 0x%lx, size 0x%lx\n",
bpa, size);
printf("bus_space_alloc: can't free region\n");
@@ -296,8 +344,7 @@ bus_space_unmap(bus_space_tag_t t, bus_s
/*
* Mark as free in the extent map.
*/
- if (extent_free(iomem_ex, bpa, size,
- EX_NOWAIT | (iomem_malloc_safe ? EX_MALLOCOK : 0))) {
+ if (extent_free(iomem_ex, bpa, size, EX_NOWAIT | iomem_malloc_safe)) {
printf("bus_space_unmap: pa 0x%lx, size 0x%lx\n", bpa, size);
printf("bus_space_unmap: can't free region\n");
}
Index: src/sys/arch/atari/atari/machdep.c
diff -u src/sys/arch/atari/atari/machdep.c:1.187 src/sys/arch/atari/atari/machdep.c:1.188
--- src/sys/arch/atari/atari/machdep.c:1.187 Sat Jul 2 08:35:49 2022
+++ src/sys/arch/atari/atari/machdep.c Sun Jul 3 16:03:08 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.187 2022/07/02 08:35:49 tsutsui Exp $ */
+/* $NetBSD: machdep.c,v 1.188 2022/07/03 16:03:08 tsutsui Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.187 2022/07/02 08:35:49 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.188 2022/07/03 16:03:08 tsutsui Exp $");
#include "opt_ddb.h"
#include "opt_compat_netbsd.h"
@@ -71,6 +71,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v
#include <sys/exec_aout.h>
#include <sys/cpu.h>
#include <sys/exec_elf.h>
+#include <sys/bus.h>
#include <uvm/uvm_extern.h>
@@ -175,7 +176,6 @@ consinit(void)
void
cpu_startup(void)
{
- extern int iomem_malloc_safe;
char pbuf[9];
#ifdef DEBUG
extern int pmapdebug;
@@ -217,7 +217,7 @@ cpu_startup(void)
/*
* Alloc extent allocation to use malloc
*/
- iomem_malloc_safe = 1;
+ atari_bus_space_malloc_set_safe();
}
/*
Index: src/sys/arch/atari/include/bus_funcs.h
diff -u src/sys/arch/atari/include/bus_funcs.h:1.1 src/sys/arch/atari/include/bus_funcs.h:1.2
--- src/sys/arch/atari/include/bus_funcs.h:1.1 Fri Jul 1 17:09:58 2011
+++ src/sys/arch/atari/include/bus_funcs.h Sun Jul 3 16:03:08 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_funcs.h,v 1.1 2011/07/01 17:09:58 dyoung Exp $ */
+/* $NetBSD: bus_funcs.h,v 1.2 2022/07/03 16:03:08 tsutsui Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -60,6 +60,14 @@
#ifndef _ATARI_BUS_FUNCS_H_
#define _ATARI_BUS_FUNCS_H_
+/* machine dependent utility functions */
+void bootm_init(vaddr_t, void *, vsize_t);
+void atari_bus_space_extent_init(paddr_t, paddr_t);
+int atari_bus_space_alloc_physmem(paddr_t, paddr_t);
+void atari_bus_space_malloc_set_safe(void);
+int atari_bus_space_extent_malloc_flag(void);
+
+/* functions for machine independent bus_space(9) API */
int bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t, bus_size_t,
bus_size_t, bus_size_t, int, bus_addr_t *, bus_space_handle_t *);
int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,