summaryrefslogtreecommitdiff
path: root/arch/arm/boot/compressed/ofw-shark.c
blob: 465c54b6b128dceeed0608c40449aeebe8dcfbcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
 * linux/arch/arm/boot/compressed/ofw-shark.c
 *
 * by Alexander Schulz
 *
 * This file is used to get some basic information
 * about the memory layout of the shark we are running
 * on. Memory is usually divided in blocks a 8 MB.
 * And bootargs are copied from OpenFirmware.
 */


#include <linux/kernel.h>
#include <linux/types.h>
#include <asm/setup.h>
#include <asm/page.h>


asmlinkage void
create_params (unsigned long *buffer)
{
	/* Is there a better address? Also change in mach-shark/core.c */
	struct tag *tag = (struct tag *) 0x08003000;
	int j,i,m,k,nr_banks,size;
	unsigned char *c;

	k = 0;

	/* Head of the taglist */
	tag->hdr.tag  = ATAG_CORE;
	tag->hdr.size = tag_size(tag_core);
	tag->u.core.flags = 1;
	tag->u.core.pagesize = PAGE_SIZE;
	tag->u.core.rootdev = 0;

	/* Build up one tagged block for each memory region */
	size=0;
	nr_banks=(unsigned int) buffer[0];
	for (j=0;j<nr_banks;j++){
		/* search the lowest address and put it into the next entry   */
		/* not a fast sort algorithm, but there are at most 8 entries */
		/* and this is used only once anyway                          */
		m=0xffffffff;
		for (i=0;i<(unsigned int) buffer[0];i++){
			if (buffer[2*i+1]<m) {
				m=buffer[2*i+1];
				k=i;
			}
		}
	  
		tag = tag_next(tag);
		tag->hdr.tag = ATAG_MEM;
		tag->hdr.size = tag_size(tag_mem32);
		tag->u.mem.size = buffer[2*k+2];
		tag->u.mem.start = buffer[2*k+1];

		size += buffer[2*k+2];

		buffer[2*k+1]=0xffffffff;                    /* mark as copied */
	}
	
	/* The command line */
	tag = tag_next(tag);
	tag->hdr.tag = ATAG_CMDLINE;
	
	c=(unsigned char *)(&buffer[34]);
	j=0;
	while (*c) tag->u.cmdline.cmdline[j++]=*c++;

	tag->u.cmdline.cmdline[j]=0;
	tag->hdr.size = (j + 7 + sizeof(struct tag_header)) >> 2;

	/* Hardware revision */
	tag = tag_next(tag);
	tag->hdr.tag = ATAG_REVISION;
	tag->hdr.size = tag_size(tag_revision);
	tag->u.revision.rev = ((unsigned char) buffer[33])-'0';

	/* End of the taglist */
	tag = tag_next(tag);
	tag->hdr.tag = 0;
	tag->hdr.size = 0;
}


typedef int (*ofw_handle_t)(void *);

/* Everything below is called with a wrong MMU setting.
 * This means: no string constants, no initialization of
 * arrays, no global variables! This is ugly but I didn't
 * want to write this in assembler :-)
 */

int
of_decode_int(const unsigned char *p)
{
	unsigned int i = *p++ << 8;
	i = (i + *p++) << 8;
	i = (i + *p++) << 8;
	return (i + *p);
}
  
int
OF_finddevice(ofw_handle_t openfirmware, char *name)
{
	unsigned int args[8];
	char service[12];

	service[0]='f';
	service[1]='i';
	service[2]='n';
	service[3]='d';
	service[4]='d';
	service[5]='e';
	service[6]='v';
	service[7]='i';
	service[8]='c';
	service[9]='e';
	service[10]='\0';

	args[0]=(unsigned int)service;
	args[1]=1;
	args[2]=1;
	args[3]=(unsigned int)name;

	if (openfirmware(args) == -1)
		return -1;
	return args[4];
}

int
OF_getproplen(ofw_handle_t openfirmware, int handle, char *prop)
{
	unsigned int args[8];
	char service[12];

	service[0]='g';
	service[1]='e';
	service[2]='t';
	service[3]='p';
	service[4]='r';
	service[5]='o';
	service[6]='p';
	service[7]='l';
	service[8]='e';
	service[9]='n';
	service[10]='\0';

	args[0] = (unsigned int)service;
	args[1] = 2;
	args[2] = 1;
	args[3] = (unsigned int)handle;
	args[4] = (unsigned int)prop;

	if (openfirmware(args) == -1)
		return -1;
	return args[5];
}
  
int
OF_getprop(ofw_handle_t openfirmware, int handle, char *prop, void *buf, unsigned int buflen)
{
	unsigned int args[8];
	char service[8];

	service[0]='g';
	service[1]='e';
	service[2]='t';
	service[3]='p';
	service[4]='r';
	service[5]='o';
	service[6]='p';
	service[7]='\0';

	args[0] = (unsigned int)service;
	args[1] = 4;
	args[2] = 1;
	args[3] = (unsigned int)handle;
	args[4] = (unsigned int)prop;
	args[5] = (unsigned int)buf;
	args[6] = buflen;

	if (openfirmware(args) == -1)
		return -1;
	return args[7];
}
  
asmlinkage void ofw_init(ofw_handle_t o, int *nomr, int *pointer)
{
	int phandle,i,mem_len,buffer[32];
	char temp[15];
  
	temp[0]='/';
	temp[1]='m';
	temp[2]='e';
	temp[3]='m';
	temp[4]='o';
	temp[5]='r';
	temp[6]='y';
	temp[7]='\0';

	phandle=OF_finddevice(o,temp);

	temp[0]='r';
	temp[1]='e';
	temp[2]='g';
	temp[3]='\0';

	mem_len = OF_getproplen(o,phandle, temp);
	OF_getprop(o,phandle, temp, buffer, mem_len);
	*nomr=mem_len >> 3;

	for (i=0; i<=mem_len/4; i++) pointer[i]=of_decode_int((const unsigned char *)&buffer[i]);

	temp[0]='/';
	temp[1]='c';
	temp[2]='h';
	temp[3]='o';
	temp[4]='s';
	temp[5]='e';
	temp[6]='n';
	temp[7]='\0';

	phandle=OF_finddevice(o,temp);

	temp[0]='b';
	temp[1]='o';
	temp[2]='o';
	temp[3]='t';
	temp[4]='a';
	temp[5]='r';
	temp[6]='g';
	temp[7]='s';
	temp[8]='\0';

	mem_len = OF_getproplen(o,phandle, temp);
	OF_getprop(o,phandle, temp, buffer, mem_len);
	if (mem_len > 128) mem_len=128;
	for (i=0; i<=mem_len/4; i++) pointer[i+33]=buffer[i];
	pointer[i+33]=0;

	temp[0]='/';
	temp[1]='\0';
	phandle=OF_finddevice(o,temp);
	temp[0]='b';
	temp[1]='a';
	temp[2]='n';
	temp[3]='n';
	temp[4]='e';
	temp[5]='r';
	temp[6]='-';
	temp[7]='n';
	temp[8]='a';
	temp[9]='m';
	temp[10]='e';
	temp[11]='\0';
	mem_len = OF_getproplen(o,phandle, temp);
	OF_getprop(o,phandle, temp, buffer, mem_len);
	* ((unsigned char *) &pointer[32]) = ((unsigned char *) buffer)[mem_len-2];
}