Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/atari Move the iomem extent stuff managed by bus_sp...



details:   https://anonhg.NetBSD.org/src/rev/d8bcd85eaa75
branches:  trunk
changeset: 368297:d8bcd85eaa75
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sun Jul 03 16:03:08 2022 +0000

description:
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.

diffstat:

 sys/arch/atari/atari/atari_init.c  |  43 +++----------------
 sys/arch/atari/atari/bus.c         |  81 ++++++++++++++++++++++++++++++-------
 sys/arch/atari/atari/machdep.c     |   8 +-
 sys/arch/atari/include/bus_funcs.h |  10 ++++-
 4 files changed, 85 insertions(+), 57 deletions(-)

diffs (truncated from 319 to 300 lines):

diff -r f4ccae990e0d -r d8bcd85eaa75 sys/arch/atari/atari/atari_init.c
--- a/sys/arch/atari/atari/atari_init.c Sun Jul 03 15:25:54 2022 +0000
+++ b/sys/arch/atari/atari/atari_init.c Sun Jul 03 16:03:08 2022 +0000
@@ -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 @@
 #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 @@
 #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 @@
        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.
+        * Initialize the iomem extent for bus_space(9) to manage address
+        * spaces and allocate the physical RAM from the extent 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
-        */
+       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 @@
        /* 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;
diff -r f4ccae990e0d -r d8bcd85eaa75 sys/arch/atari/atari/bus.c
--- a/sys/arch/atari/atari/bus.c        Sun Jul 03 15:25:54 2022 +0000
+++ b/sys/arch/atari/atari/bus.c        Sun Jul 03 16:03:08 2022 +0000
@@ -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 @@
 #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_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 @@
                                                                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 @@
        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 @@
         * 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 @@
         */
        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 @@
         */
        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 @@
        /*
         * 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");
        }
diff -r f4ccae990e0d -r d8bcd85eaa75 sys/arch/atari/atari/machdep.c
--- a/sys/arch/atari/atari/machdep.c    Sun Jul 03 15:25:54 2022 +0000
+++ b/sys/arch/atari/atari/machdep.c    Sun Jul 03 16:03:08 2022 +0000
@@ -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 @@
 #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 @@
 void
 cpu_startup(void)
 {
-       extern int iomem_malloc_safe;
        char pbuf[9];
 #ifdef DEBUG
        extern int pmapdebug;
@@ -217,7 +217,7 @@
        /*
         * Alloc extent allocation to use malloc
         */
-       iomem_malloc_safe = 1;
+       atari_bus_space_malloc_set_safe();
 }
 
 /*
diff -r f4ccae990e0d -r d8bcd85eaa75 sys/arch/atari/include/bus_funcs.h
--- a/sys/arch/atari/include/bus_funcs.h        Sun Jul 03 15:25:54 2022 +0000
+++ b/sys/arch/atari/include/bus_funcs.h        Sun Jul 03 16:03:08 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_funcs.h,v 1.1 2011/07/01 17:09:58 dyoung Exp $     */



Home | Main Index | Thread Index | Old Index