OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [m68k/] [atari/] [stram.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1623 jcastillo
 
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
  /* initialize start boundary */
33
  dp = DP (stramaddr);
34
  dp->first = 1;
35
  dp->alloced = 0;
36
  dp->length = stramsize - 2 * sizeof (*dp);
37
 
38
  /* initialize end boundary */
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
  /* last chunk */
54
  struct stram_desc *dp;
55
  void *ptr;
56
 
57
  /* round off */
58
  size = (size + 3) & ~3;
59
 
60
#ifdef DEBUG
61
  printk ("stram_alloc: allocate %ld bytes\n", size);
62
#endif
63
 
64
  /*
65
   * get pointer to descriptor for last chunk by
66
   * going backwards from end chunk
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
      /* length too small to split; allocate the whole thing */
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
      /* split the extent; use the end part */
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
  /* deallocate the chunk */
128
  sdp->alloced = edp->alloced = 0;
129
 
130
  /* check if we should merge with the previous chunk */
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
  /* check if we should merge with the following chunk */
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
/* ++roman:
154
 *
155
 * New version of ST-Ram buffer allocation. Instead of using the
156
 * 1 MB - 4 KB that remain when the ST-Ram chunk starts at $1000
157
 * (1 MB granularity!), such buffers are reserved like this:
158
 *
159
 *  - If the kernel resides in ST-Ram anyway, we can take the buffer
160
 *    from behind the current kernel data space the normal way
161
 *    (incrementing start_mem).
162
 *
163
 *  - If the kernel is in TT-Ram, stram_init() initializes start and
164
 *    end of the available region. Buffers are allocated from there
165
 *    and mem_init() later marks the such used pages as reserved.
166
 *    Since each TT-Ram chunk is at least 4 MB in size, I hope there
167
 *    won't be an overrun of the ST-Ram region by normal kernel data
168
 *    space.
169
 *
170
 * For that, ST-Ram may only be allocated while kernel initialization
171
 * is going on, or exactly: before mem_init() is called. There is also
172
 * no provision now for freeing ST-Ram buffers. It seems that isn't
173
 * really needed.
174
 *
175
 * ToDo:
176
 * Check the high level scsi code what is done when the
177
 * UNCHECKED_ISA_DMA flag is set. It guess, it is just a test for adr
178
 * < 16 Mega. There should be call to atari_stram_alloc() instead.
179
 *
180
 * Also ToDo:
181
 * Go through head.S and delete parts no longer needed (transparent
182
 * mapping of ST-Ram etc.)
183
 *
184
 */
185
 
186
 
187
unsigned long rsvd_stram_beg, rsvd_stram_end;
188
    /* Start and end of the reserved ST-Ram region */
189
static unsigned long stram_end;
190
    /* Overall end of ST-Ram */
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 ); /* skip super-only first 2 KB! */
200
                        rsvd_stram_end = rsvd_stram_beg;
201
                        stram_end = rsvd_stram_beg - 0x800 + boot_info.memory[i].size;
202
                        return;
203
                }
204
        }
205
        /* Should never come here! (There is always ST-Ram!) */
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
                /* Get memory from kernel data space */
221
                adr = (void *) *start_mem;
222
                *start_mem += size;
223
        }
224
        else {
225
                /* Get memory from rsvd_stram_beg */
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
        /* Sorry, this is a dummy. It isn't needed anyway. */
239
}
240
 
241
#endif
242
 
243
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.