This source file includes following definitions.
- atari_stram_init
- atari_stram_alloc
- atari_stram_free
- atari_stram_init
- atari_stram_alloc
- atari_stram_free
1
2 #include <linux/types.h>
3 #include <linux/kernel.h>
4 #include <linux/mm.h>
5 #include <asm/bootinfo.h>
6 #include <asm/atarihw.h>
7 #include <asm/page.h>
8 #include <asm/pgtable.h>
9
10 #if 0
11
12 struct stram_desc
13 {
14 unsigned first:1;
15 unsigned last:1;
16 unsigned alloced:1;
17 unsigned length:24;
18 };
19
20 #define DP(ptr) ((struct stram_desc *) (ptr))
21
22 static unsigned long stramsize;
23 static unsigned long stramaddr;
24
25 void
26 atari_stram_init (void)
27 {
28 struct stram_desc *dp;
29 stramaddr = boot_info.bi_atari.stram_start;
30 stramsize = boot_info.bi_atari.stram_size;
31
32
33 dp = DP (stramaddr);
34 dp->first = 1;
35 dp->alloced = 0;
36 dp->length = stramsize - 2 * sizeof (*dp);
37
38
39 dp = DP (stramaddr + stramsize) - 1;
40 dp->last = 1;
41 dp->alloced = 0;
42 dp->length = stramsize - 2 * sizeof (*dp);
43
44 #ifdef DEBUG
45 printk ("stram end boundary is %p, length is %d\n", dp,
46 dp->length);
47 #endif
48 }
49
50 void *
51 atari_stram_alloc (long size)
52 {
53
54 struct stram_desc *dp;
55 void *ptr;
56
57
58 size = (size + 3) & ~3;
59
60 #ifdef DEBUG
61 printk ("stram_alloc: allocate %ld bytes\n", size);
62 #endif
63
64
65
66
67
68 dp = DP (stramaddr + stramsize) - 1;
69 dp = DP ((unsigned long) dp - dp->length) - 1;
70
71 while ((dp->alloced || dp->length < size) && !dp->first)
72 dp = DP ((unsigned long) dp - dp[-1].length) - 2;
73
74 if (dp->alloced || dp->length < size)
75 {
76 printk ("no stram available for %ld allocation\n", size);
77 return NULL;
78 }
79
80 if (dp->length < size + 2 * sizeof (*dp))
81 {
82
83 dp->alloced = 1;
84 ptr = (void *) (dp + 1);
85 dp = DP ((unsigned long) ptr + dp->length);
86 dp->alloced = 1;
87 #ifdef DEBUG
88 printk ("stram_alloc: no split\n");
89 #endif
90 }
91 else
92 {
93
94 long newsize = dp->length - (2 * sizeof (*dp) + size);
95
96 #ifdef DEBUG
97 printk ("stram_alloc: splitting %d to %ld\n", dp->length,
98 newsize);
99 #endif
100 dp->length = newsize;
101 dp = DP ((unsigned long) (dp + 1) + newsize);
102 dp->first = dp->last = 0;
103 dp->alloced = 0;
104 dp->length = newsize;
105 dp++;
106 dp->first = dp->last = 0;
107 dp->alloced = 1;
108 dp->length = size;
109 ptr = (void *) (dp + 1);
110 dp = DP ((unsigned long) ptr + size);
111 dp->alloced = 1;
112 dp->length = size;
113 }
114
115 #ifdef DEBUG
116 printk ("stram_alloc: returning %p\n", ptr);
117 #endif
118 return ptr;
119 }
120
121 void
122 atari_stram_free (void *ptr)
123 {
124 struct stram_desc *sdp = DP (ptr) - 1, *dp2;
125 struct stram_desc *edp = DP ((unsigned long) ptr + sdp->length);
126
127
128 sdp->alloced = edp->alloced = 0;
129
130
131 if (!sdp->first && !sdp[-1].alloced)
132 {
133 dp2 = DP ((unsigned long) sdp - sdp[-1].length) - 2;
134 dp2->length += sdp->length + 2 * sizeof (*sdp);
135 edp->length = dp2->length;
136 sdp = dp2;
137 }
138
139
140 if (!edp->last && !edp[1].alloced)
141 {
142 dp2 = DP ((unsigned long) edp + edp[1].length) + 2;
143 dp2->length += edp->length + 2 * sizeof (*sdp);
144 sdp->length = dp2->length;
145 edp = dp2;
146 }
147 }
148
149 #else
150
151 #include <linux/mm.h>
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187 unsigned long rsvd_stram_beg, rsvd_stram_end;
188
189 static unsigned long stram_end;
190
191
192
193 void atari_stram_init( void )
194
195 { int i;
196
197 for( i = 0; i < boot_info.num_memory; ++i ) {
198 if (boot_info.memory[i].addr == 0) {
199 rsvd_stram_beg = PTOV( 0x800 );
200 rsvd_stram_end = rsvd_stram_beg;
201 stram_end = rsvd_stram_beg - 0x800 + boot_info.memory[i].size;
202 return;
203 }
204 }
205
206 }
207
208
209 void *atari_stram_alloc( long size, unsigned long *start_mem )
210
211 {
212 static int kernel_in_stram = -1;
213
214 void *adr = 0;
215
216 if (kernel_in_stram < 0)
217 kernel_in_stram = (PTOV( 0 ) == 0);
218
219 if (kernel_in_stram) {
220
221 adr = (void *) *start_mem;
222 *start_mem += size;
223 }
224 else {
225
226 if (rsvd_stram_end + size < stram_end) {
227 adr = (void *) rsvd_stram_end;
228 rsvd_stram_end += size;
229 }
230 }
231
232 return( adr );
233 }
234
235 void atari_stram_free( void *ptr )
236
237 {
238
239 }
240
241 #endif
242
243