Path: blob/master/arch/arm/boot/compressed/ofw-shark.c
10819 views
/*1* linux/arch/arm/boot/compressed/ofw-shark.c2*3* by Alexander Schulz4*5* This file is used to get some basic information6* about the memory layout of the shark we are running7* on. Memory is usually divided in blocks a 8 MB.8* And bootargs are copied from OpenFirmware.9*/101112#include <linux/kernel.h>13#include <linux/types.h>14#include <asm/setup.h>15#include <asm/page.h>161718asmlinkage void19create_params (unsigned long *buffer)20{21/* Is there a better address? Also change in mach-shark/core.c */22struct tag *tag = (struct tag *) 0x08003000;23int j,i,m,k,nr_banks,size;24unsigned char *c;2526k = 0;2728/* Head of the taglist */29tag->hdr.tag = ATAG_CORE;30tag->hdr.size = tag_size(tag_core);31tag->u.core.flags = 1;32tag->u.core.pagesize = PAGE_SIZE;33tag->u.core.rootdev = 0;3435/* Build up one tagged block for each memory region */36size=0;37nr_banks=(unsigned int) buffer[0];38for (j=0;j<nr_banks;j++){39/* search the lowest address and put it into the next entry */40/* not a fast sort algorithm, but there are at most 8 entries */41/* and this is used only once anyway */42m=0xffffffff;43for (i=0;i<(unsigned int) buffer[0];i++){44if (buffer[2*i+1]<m) {45m=buffer[2*i+1];46k=i;47}48}4950tag = tag_next(tag);51tag->hdr.tag = ATAG_MEM;52tag->hdr.size = tag_size(tag_mem32);53tag->u.mem.size = buffer[2*k+2];54tag->u.mem.start = buffer[2*k+1];5556size += buffer[2*k+2];5758buffer[2*k+1]=0xffffffff; /* mark as copied */59}6061/* The command line */62tag = tag_next(tag);63tag->hdr.tag = ATAG_CMDLINE;6465c=(unsigned char *)(&buffer[34]);66j=0;67while (*c) tag->u.cmdline.cmdline[j++]=*c++;6869tag->u.cmdline.cmdline[j]=0;70tag->hdr.size = (j + 7 + sizeof(struct tag_header)) >> 2;7172/* Hardware revision */73tag = tag_next(tag);74tag->hdr.tag = ATAG_REVISION;75tag->hdr.size = tag_size(tag_revision);76tag->u.revision.rev = ((unsigned char) buffer[33])-'0';7778/* End of the taglist */79tag = tag_next(tag);80tag->hdr.tag = 0;81tag->hdr.size = 0;82}838485typedef int (*ofw_handle_t)(void *);8687/* Everything below is called with a wrong MMU setting.88* This means: no string constants, no initialization of89* arrays, no global variables! This is ugly but I didn't90* want to write this in assembler :-)91*/9293int94of_decode_int(const unsigned char *p)95{96unsigned int i = *p++ << 8;97i = (i + *p++) << 8;98i = (i + *p++) << 8;99return (i + *p);100}101102int103OF_finddevice(ofw_handle_t openfirmware, char *name)104{105unsigned int args[8];106char service[12];107108service[0]='f';109service[1]='i';110service[2]='n';111service[3]='d';112service[4]='d';113service[5]='e';114service[6]='v';115service[7]='i';116service[8]='c';117service[9]='e';118service[10]='\0';119120args[0]=(unsigned int)service;121args[1]=1;122args[2]=1;123args[3]=(unsigned int)name;124125if (openfirmware(args) == -1)126return -1;127return args[4];128}129130int131OF_getproplen(ofw_handle_t openfirmware, int handle, char *prop)132{133unsigned int args[8];134char service[12];135136service[0]='g';137service[1]='e';138service[2]='t';139service[3]='p';140service[4]='r';141service[5]='o';142service[6]='p';143service[7]='l';144service[8]='e';145service[9]='n';146service[10]='\0';147148args[0] = (unsigned int)service;149args[1] = 2;150args[2] = 1;151args[3] = (unsigned int)handle;152args[4] = (unsigned int)prop;153154if (openfirmware(args) == -1)155return -1;156return args[5];157}158159int160OF_getprop(ofw_handle_t openfirmware, int handle, char *prop, void *buf, unsigned int buflen)161{162unsigned int args[8];163char service[8];164165service[0]='g';166service[1]='e';167service[2]='t';168service[3]='p';169service[4]='r';170service[5]='o';171service[6]='p';172service[7]='\0';173174args[0] = (unsigned int)service;175args[1] = 4;176args[2] = 1;177args[3] = (unsigned int)handle;178args[4] = (unsigned int)prop;179args[5] = (unsigned int)buf;180args[6] = buflen;181182if (openfirmware(args) == -1)183return -1;184return args[7];185}186187asmlinkage void ofw_init(ofw_handle_t o, int *nomr, int *pointer)188{189int phandle,i,mem_len,buffer[32];190char temp[15];191192temp[0]='/';193temp[1]='m';194temp[2]='e';195temp[3]='m';196temp[4]='o';197temp[5]='r';198temp[6]='y';199temp[7]='\0';200201phandle=OF_finddevice(o,temp);202203temp[0]='r';204temp[1]='e';205temp[2]='g';206temp[3]='\0';207208mem_len = OF_getproplen(o,phandle, temp);209OF_getprop(o,phandle, temp, buffer, mem_len);210*nomr=mem_len >> 3;211212for (i=0; i<=mem_len/4; i++) pointer[i]=of_decode_int((const unsigned char *)&buffer[i]);213214temp[0]='/';215temp[1]='c';216temp[2]='h';217temp[3]='o';218temp[4]='s';219temp[5]='e';220temp[6]='n';221temp[7]='\0';222223phandle=OF_finddevice(o,temp);224225temp[0]='b';226temp[1]='o';227temp[2]='o';228temp[3]='t';229temp[4]='a';230temp[5]='r';231temp[6]='g';232temp[7]='s';233temp[8]='\0';234235mem_len = OF_getproplen(o,phandle, temp);236OF_getprop(o,phandle, temp, buffer, mem_len);237if (mem_len > 128) mem_len=128;238for (i=0; i<=mem_len/4; i++) pointer[i+33]=buffer[i];239pointer[i+33]=0;240241temp[0]='/';242temp[1]='\0';243phandle=OF_finddevice(o,temp);244temp[0]='b';245temp[1]='a';246temp[2]='n';247temp[3]='n';248temp[4]='e';249temp[5]='r';250temp[6]='-';251temp[7]='n';252temp[8]='a';253temp[9]='m';254temp[10]='e';255temp[11]='\0';256mem_len = OF_getproplen(o,phandle, temp);257OF_getprop(o,phandle, temp, buffer, mem_len);258* ((unsigned char *) &pointer[32]) = ((unsigned char *) buffer)[mem_len-2];259}260261262