aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k/atari/stram.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/m68k/atari/stram.c')
-rw-r--r--arch/m68k/atari/stram.c71
1 files changed, 54 insertions, 17 deletions
diff --git a/arch/m68k/atari/stram.c b/arch/m68k/atari/stram.c
index 0810c8d56e59..5f8cb5a234d9 100644
--- a/arch/m68k/atari/stram.c
+++ b/arch/m68k/atari/stram.c
@@ -47,6 +47,7 @@ static struct resource stram_pool = {
47 47
48static unsigned long pool_size = 1024*1024; 48static unsigned long pool_size = 1024*1024;
49 49
50static unsigned long stram_virt_offset;
50 51
51static int __init atari_stram_setup(char *arg) 52static int __init atari_stram_setup(char *arg)
52{ 53{
@@ -67,14 +68,12 @@ early_param("stram_pool", atari_stram_setup);
67void __init atari_stram_init(void) 68void __init atari_stram_init(void)
68{ 69{
69 int i; 70 int i;
70 void *stram_start;
71 71
72 /* 72 /*
73 * determine whether kernel code resides in ST-RAM 73 * determine whether kernel code resides in ST-RAM
74 * (then ST-RAM is the first memory block at virtual 0x0) 74 * (then ST-RAM is the first memory block at virtual 0x0)
75 */ 75 */
76 stram_start = phys_to_virt(0); 76 kernel_in_stram = (m68k_memory[0].addr == 0);
77 kernel_in_stram = (stram_start == 0);
78 77
79 for (i = 0; i < m68k_num_memory; ++i) { 78 for (i = 0; i < m68k_num_memory; ++i) {
80 if (m68k_memory[i].addr == 0) { 79 if (m68k_memory[i].addr == 0) {
@@ -89,24 +88,62 @@ void __init atari_stram_init(void)
89 88
90/* 89/*
91 * This function is called from setup_arch() to reserve the pages needed for 90 * This function is called from setup_arch() to reserve the pages needed for
92 * ST-RAM management. 91 * ST-RAM management, if the kernel resides in ST-RAM.
93 */ 92 */
94void __init atari_stram_reserve_pages(void *start_mem) 93void __init atari_stram_reserve_pages(void *start_mem)
95{ 94{
96 /* 95 if (kernel_in_stram) {
97 * always reserve first page of ST-RAM, the first 2 KiB are 96 pr_debug("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n");
98 * supervisor-only! 97 stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
99 */ 98 stram_pool.end = stram_pool.start + pool_size - 1;
100 if (!kernel_in_stram) 99 request_resource(&iomem_resource, &stram_pool);
101 reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT); 100 stram_virt_offset = 0;
101 pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n",
102 pool_size, &stram_pool);
103 pr_debug("atari_stram pool: stram_virt_offset = %lx\n",
104 stram_virt_offset);
105 }
106}
102 107
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);
106 108
107 pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n", 109/*
108 pool_size, &stram_pool); 110 * This function is called as arch initcall to reserve the pages needed for
111 * ST-RAM management, if the kernel does not reside in ST-RAM.
112 */
113int __init atari_stram_map_pages(void)
114{
115 if (!kernel_in_stram) {
116 /*
117 * Skip page 0, as the fhe first 2 KiB are supervisor-only!
118 */
119 pr_debug("atari_stram pool: kernel not in ST-RAM, using ioremap!\n");
120 stram_pool.start = PAGE_SIZE;
121 stram_pool.end = stram_pool.start + pool_size - 1;
122 request_resource(&iomem_resource, &stram_pool);
123 stram_virt_offset = (unsigned long) ioremap(stram_pool.start,
124 resource_size(&stram_pool)) - stram_pool.start;
125 pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n",
126 pool_size, &stram_pool);
127 pr_debug("atari_stram pool: stram_virt_offset = %lx\n",
128 stram_virt_offset);
129 }
130 return 0;
131}
132arch_initcall(atari_stram_map_pages);
133
134
135void *atari_stram_to_virt(unsigned long phys)
136{
137 return (void *)(phys + stram_virt_offset);
138}
139EXPORT_SYMBOL(atari_stram_to_virt);
140
141
142unsigned long atari_stram_to_phys(void *virt)
143{
144 return (unsigned long)(virt - stram_virt_offset);
109} 145}
146EXPORT_SYMBOL(atari_stram_to_phys);
110 147
111 148
112void *atari_stram_alloc(unsigned long size, const char *owner) 149void *atari_stram_alloc(unsigned long size, const char *owner)
@@ -134,14 +171,14 @@ void *atari_stram_alloc(unsigned long size, const char *owner)
134 } 171 }
135 172
136 pr_debug("atari_stram_alloc: returning %pR\n", res); 173 pr_debug("atari_stram_alloc: returning %pR\n", res);
137 return (void *)res->start; 174 return atari_stram_to_virt(res->start);
138} 175}
139EXPORT_SYMBOL(atari_stram_alloc); 176EXPORT_SYMBOL(atari_stram_alloc);
140 177
141 178
142void atari_stram_free(void *addr) 179void atari_stram_free(void *addr)
143{ 180{
144 unsigned long start = (unsigned long)addr; 181 unsigned long start = atari_stram_to_phys(addr);
145 struct resource *res; 182 struct resource *res;
146 unsigned long size; 183 unsigned long size;
147 184