Changeset 38fe9d0 in mainline for arch/ppc32/loader/ofw.c


Ignore:
Timestamp:
2006-04-02T15:10:41Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
89343aac
Parents:
730de779
Message:

add instruction cache flush
align framebuffer on 128K boundary
change OFW calling method
make OFW code more compatible

File:
1 edited

Legend:

Unmodified
Added
Removed
  • arch/ppc32/loader/ofw.c

    r730de779 r38fe9d0  
    3232
    3333#define MAX_OFW_ARGS    10
    34 #define STRING_SIZE             1024
     34#define BUF_SIZE                1024
    3535
    3636typedef unsigned int ofw_arg_t;
     
    5454
    5555phandle ofw_chosen;
     56ihandle ofw_stdout;
     57phandle ofw_root;
     58ihandle ofw_mmu;
     59phandle ofw_memory;
    5660phandle ofw_aliases;
    57 ihandle ofw_mmu;
    58 ihandle ofw_stdout;
    59 
    60 
    61 static int ofw_call(const char *service, const int nargs, const int nret, ...)
     61
     62
     63static int ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
    6264{
    6365        va_list list;
     
    6971        args.nret = nret;
    7072       
    71         va_start(list, nret);
     73        va_start(list, rets);
    7274        for (i = 0; i < nargs; i++)
    7375                args.args[i] = va_arg(list, ofw_arg_t);
     
    7981        ofw(&args);
    8082       
     83        for (i = 1; i < nret; i++)
     84                rets[i - 1] = args.args[i + nargs];
     85       
    8186        return args.args[nargs];
    8287}
     
    8590static phandle ofw_find_device(const char *name)
    8691{
    87         return ofw_call("finddevice", 1, 1, name);
     92        return ofw_call("finddevice", 1, 1, NULL, name);
    8893}
    8994
     
    9196static int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen)
    9297{
    93         return ofw_call("getprop", 4, 1, device, name, buf, buflen);
    94 }
     98        return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
     99}
     100
     101
     102static unsigned int ofw_get_address_cells(const phandle device)
     103{
     104        unsigned int ret;
     105       
     106        if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
     107                if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
     108                        ret = 1;
     109       
     110        return ret;
     111}
     112
     113
     114static unsigned int ofw_get_size_cells(const phandle device)
     115{
     116        unsigned int ret;
     117       
     118        if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
     119                if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
     120                        ret = 1;
     121       
     122        return ret;
     123}
     124
    95125
    96126static ihandle ofw_open(const char *name)
    97127{
    98         return ofw_call("open", 1, 1, name);
     128        return ofw_call("open", 1, 1, NULL, name);
    99129}
    100130
     
    106136                halt();
    107137       
    108         if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)     
     138        if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
    109139                ofw_stdout = 0;
     140       
     141        ofw_root = ofw_find_device("/");
     142        if (ofw_root == -1) {
     143                puts("\r\nError: Unable to find / device, halted.\r\n");
     144                halt();
     145        }
     146       
     147        if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
     148                puts("\r\nError: Unable to get mmu property, halted.\r\n");
     149                halt();
     150        }
     151       
     152        ofw_memory = ofw_find_device("/memory");
     153        if (ofw_memory == -1) {
     154                puts("\r\nError: Unable to find /memory device, halted.\r\n");
     155                halt();
     156        }
    110157       
    111158        ofw_aliases = ofw_find_device("/aliases");
    112159        if (ofw_aliases == -1) {
    113                 puts("\nUnable to find /aliases device\n");
    114                 halt();
    115         }
    116        
    117         ofw_mmu = ofw_open("/mmu");
    118         if (ofw_mmu == -1) {
    119                 puts("\nUnable to open /mmu node\n");
     160                puts("\r\nError: Unable to find /aliases device, halted.\r\n");
    120161                halt();
    121162        }
     
    128169                return;
    129170       
    130         ofw_call("write", 3, 1, ofw_stdout, str, len);
     171        ofw_call("write", 3, 1, NULL, ofw_stdout, str, len);
    131172}
    132173
     
    134175void *ofw_translate(const void *virt)
    135176{
    136         return (void *) ofw_call("call-method", 7, 1, "translate", ofw_mmu, virt, 0, 0, 0, 0);
     177        ofw_arg_t result[3];
     178       
     179        if (ofw_call("call-method", 4, 4, result, "translate", ofw_mmu, virt, 1) != 0) {
     180                puts("Error: MMU method translate() failed, halting.\n");
     181                halt();
     182        }
     183        return (void *) result[2];
    137184}
    138185
     
    140187int ofw_map(const void *phys, const void *virt, const int size, const int mode)
    141188{
    142         return ofw_call("call-method", 6, 1, "map", ofw_mmu, mode, size, virt, phys);
     189        return ofw_call("call-method", 6, 1, NULL, "map", ofw_mmu, mode, size, virt, phys);
    143190}
    144191
     
    146193int ofw_memmap(memmap_t *map)
    147194{
    148         int i;
    149         int ret;
    150 
    151         phandle handle = ofw_find_device("/memory");
    152         if (handle == -1)
    153                 return false;
    154        
    155         ret = ofw_get_property(handle, "reg", &map->zones, sizeof(map->zones));
    156         if (ret == -1)
    157                 return false;
    158        
     195        unsigned int buf[BUF_SIZE];
     196        int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned int) * BUF_SIZE);
     197        if (ret <= 0)
     198                return false;
     199               
     200        unsigned int ac = ofw_get_address_cells(ofw_memory);
     201        unsigned int sc = ofw_get_size_cells(ofw_memory);
     202       
     203        int pos;
    159204        map->total = 0;
    160205        map->count = 0;
    161         for (i = 0; i < MEMMAP_MAX_RECORDS; i++) {
    162                 if (map->zones[i].size == 0)
    163                         break;
    164                 map->count++;
    165                 map->total += map->zones[i].size;
     206        for (pos = 0; (pos < ret / sizeof(unsigned int)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
     207                void * start = (void *) buf[pos + ac - 1];
     208                unsigned int size = buf[pos + ac + sc - 1];
     209               
     210                if (size > 0) {
     211                        map->zones[map->count].start = start;
     212                        map->zones[map->count].size = size;
     213                        map->count++;
     214                        map->total += size;
     215                }
    166216        }
    167217}
     
    170220int ofw_screen(screen_t *screen)
    171221{
    172         char device_name[STRING_SIZE];
    173        
    174         if (ofw_get_property(ofw_aliases, "screen", device_name, STRING_SIZE) <= 0)
     222        char device_name[BUF_SIZE];
     223       
     224        if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(char) * BUF_SIZE) <= 0)
    175225                return false;
    176226       
Note: See TracChangeset for help on using the changeset viewer.