Changeset 63cda71 in mainline for boot/genarch/ofw.c


Ignore:
Timestamp:
2006-07-13T14:58:57Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
94d614e
Parents:
eda7bf81
Message:

Fix ofw_memmap() in boot infrastructure.
The cell size is 32-bit and not equal sizeof(ofw_arg_t).
Define architecture dependant #address-cells and #size-cells for cases
the respective properties are missing in the OpenFirmware device tree.
The algorithm now works both for ppc32 and sparc64.

Add memmap_t, screen_t and keyboard_t to sparc64 bootinfo structure.
Be more verbose during sparc64 boot.

Move ALIGN_UP to generic part of boot/.

Change header guards in several places so that they don't contain double underscore.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • boot/genarch/ofw.c

    reda7bf81 r63cda71  
    2727 */
    2828 
    29 #include "ofw.h"
     29#include <ofw.h>
     30#include <ofwarch.h>
    3031#include <printf.h>
    3132#include <asm.h>
     
    4142phandle ofw_aliases;
    4243
     44void ofw_init(void)
     45{
     46        ofw_chosen = ofw_find_device("/chosen");
     47        if (ofw_chosen == -1)
     48                halt();
     49       
     50        if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
     51                ofw_stdout = 0;
     52       
     53        ofw_root = ofw_find_device("/");
     54        if (ofw_root == -1) {
     55                puts("\r\nError: Unable to find / device, halted.\r\n");
     56                halt();
     57        }
     58       
     59        if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
     60                puts("\r\nError: Unable to get mmu property, halted.\r\n");
     61                halt();
     62        }
     63
     64        ofw_memory = ofw_find_device("/memory");
     65        if (ofw_memory == -1) {
     66                puts("\r\nError: Unable to find /memory device, halted.\r\n");
     67                halt();
     68        }
     69       
     70        ofw_aliases = ofw_find_device("/aliases");
     71        if (ofw_aliases == -1) {
     72                puts("\r\nError: Unable to find /aliases device, halted.\r\n");
     73                halt();
     74        }
     75}
     76
     77
    4378static unsigned long ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
    4479{
     
    80115
    81116
    82 static unsigned int ofw_get_address_cells(const phandle device)
    83 {
    84         unsigned int ret;
     117unsigned int ofw_get_address_cells(const phandle device)
     118{
     119        unsigned int ret = 1;
    85120       
    86121        if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
    87122                if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
    88                         ret = 1;
     123                        ret = OFW_ADDRESS_CELLS;
    89124       
    90125        return ret;
     
    92127
    93128
    94 static unsigned int ofw_get_size_cells(const phandle device)
     129unsigned int ofw_get_size_cells(const phandle device)
    95130{
    96131        unsigned int ret;
     
    98133        if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
    99134                if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
    100                         ret = 1;
     135                        ret = OFW_SIZE_CELLS;
    101136       
    102137        return ret;
     
    107142{
    108143        return ofw_call("open", 1, 1, NULL, name);
    109 }
    110 
    111 
    112 void init(void)
    113 {
    114         ofw_chosen = ofw_find_device("/chosen");
    115         if (ofw_chosen == -1)
    116                 halt();
    117        
    118         if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
    119                 ofw_stdout = 0;
    120        
    121         ofw_root = ofw_find_device("/");
    122         if (ofw_root == -1) {
    123                 puts("\r\nError: Unable to find / device, halted.\r\n");
    124                 halt();
    125         }
    126        
    127         if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
    128                 puts("\r\nError: Unable to get mmu property, halted.\r\n");
    129                 halt();
    130         }
    131        
    132         ofw_memory = ofw_find_device("/memory");
    133         if (ofw_memory == -1) {
    134                 puts("\r\nError: Unable to find /memory device, halted.\r\n");
    135                 halt();
    136         }
    137        
    138         ofw_aliases = ofw_find_device("/aliases");
    139         if (ofw_aliases == -1) {
    140                 puts("\r\nError: Unable to find /aliases device, halted.\r\n");
    141                 halt();
    142         }
    143144}
    144145
     
    170171        else
    171172                shift = 0;
    172                
     173
    173174        return (void *) ((result[2]<<shift)|result[3]);
    174175}
     
    207208int ofw_memmap(memmap_t *map)
    208209{
    209         unsigned long buf[BUF_SIZE];
    210         int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf));
    211         if (ret <= 0)
    212                 return false;
    213                
    214210        unsigned int ac = ofw_get_address_cells(ofw_memory);
    215211        unsigned int sc = ofw_get_size_cells(ofw_memory);
    216        
     212
     213        uint32_t buf[((ac+sc)*MEMMAP_MAX_RECORDS)];
     214        int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf));
     215        if (ret <= 0)           /* ret is the number of written bytes */
     216                return false;
     217
    217218        int pos;
    218219        map->total = 0;
    219220        map->count = 0;
    220         for (pos = 0; (pos < ret / sizeof(unsigned long)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
    221                 void * start = (void *) buf[pos + ac - 1];
     221        for (pos = 0; (pos < ret / sizeof(uint32_t)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
     222                void * start = (void *) ((uintptr_t) buf[pos + ac - 1]);
    222223                unsigned int size = buf[pos + ac + sc - 1];
    223224               
     
    229230                }
    230231        }
     232       
     233        return true;
    231234}
    232235
     
    235238{
    236239        char device_name[BUF_SIZE];
     240        uint32_t virtaddr;
    237241       
    238242        if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0)
     
    243247                return false;
    244248       
    245         if (ofw_get_property(device, "address", &screen->addr, sizeof(screen->addr)) <= 0)
    246                 return false;
    247        
     249        if (ofw_get_property(device, "address", &virtaddr, sizeof(virtaddr)) <= 0)
     250                return false;
     251
     252        screen->addr = (void *) ((uintptr_t) virtaddr);
     253
    248254        if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0)
    249255                return false;
Note: See TracChangeset for help on using the changeset viewer.