2 * Functions for ST-RAM allocations
4 * Copyright 1994-97 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
11 #include <linux/types.h>
12 #include <linux/kernel.h>
14 #include <linux/kdev_t.h>
15 #include <linux/major.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/vmalloc.h>
19 #include <linux/pagemap.h>
20 #include <linux/bootmem.h>
21 #include <linux/mount.h>
22 #include <linux/blkdev.h>
23 #include <linux/module.h>
25 #include <asm/setup.h>
26 #include <asm/machdep.h>
28 #include <asm/pgtable.h>
29 #include <asm/atarihw.h>
30 #include <asm/atari_stram.h>
35 * The ST-RAM allocator allocates memory from a pool of reserved ST-RAM of
36 * configurable size, set aside on ST-RAM init.
37 * As long as this pool is not exhausted, allocation of real ST-RAM can be
41 /* set if kernel is in ST-RAM */
42 static int kernel_in_stram
;
44 static struct resource stram_pool
= {
48 static unsigned long pool_size
= 1024*1024;
51 static int __init
atari_stram_setup(char *arg
)
56 pool_size
= memparse(arg
, NULL
);
60 early_param("stram_pool", atari_stram_setup
);
64 * This init function is called very early by atari/config.c
65 * It initializes some internal variables needed for stram_alloc()
67 void __init
atari_stram_init(void)
73 * determine whether kernel code resides in ST-RAM
74 * (then ST-RAM is the first memory block at virtual 0x0)
76 stram_start
= phys_to_virt(0);
77 kernel_in_stram
= (stram_start
== 0);
79 for (i
= 0; i
< m68k_num_memory
; ++i
) {
80 if (m68k_memory
[i
].addr
== 0) {
85 /* Should never come here! (There is always ST-Ram!) */
86 panic("atari_stram_init: no ST-RAM found!");
91 * This function is called from setup_arch() to reserve the pages needed for
94 void __init
atari_stram_reserve_pages(void *start_mem
)
97 * always reserve first page of ST-RAM, the first 2 KiB are
100 if (!kernel_in_stram
)
101 reserve_bootmem(0, PAGE_SIZE
, BOOTMEM_DEFAULT
);
103 stram_pool
.start
= (resource_size_t
)alloc_bootmem_low_pages(pool_size
);
104 stram_pool
.end
= stram_pool
.start
+ pool_size
- 1;
105 request_resource(&iomem_resource
, &stram_pool
);
107 pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n",
108 pool_size
, &stram_pool
);
112 void *atari_stram_alloc(unsigned long size
, const char *owner
)
114 struct resource
*res
;
117 pr_debug("atari_stram_alloc: allocate %lu bytes\n", size
);
120 size
= PAGE_ALIGN(size
);
122 res
= kzalloc(sizeof(struct resource
), GFP_KERNEL
);
127 error
= allocate_resource(&stram_pool
, res
, size
, 0, UINT_MAX
,
128 PAGE_SIZE
, NULL
, NULL
);
130 pr_err("atari_stram_alloc: allocate_resource() failed %d!\n",
136 pr_debug("atari_stram_alloc: returning %pR\n", res
);
137 return (void *)res
->start
;
139 EXPORT_SYMBOL(atari_stram_alloc
);
142 void atari_stram_free(void *addr
)
144 unsigned long start
= (unsigned long)addr
;
145 struct resource
*res
;
148 res
= lookup_resource(&stram_pool
, start
);
150 pr_err("atari_stram_free: trying to free nonexistent region "
155 size
= resource_size(res
);
156 pr_debug("atari_stram_free: free %lu bytes at %p\n", size
, addr
);
157 release_resource(res
);
160 EXPORT_SYMBOL(atari_stram_free
);