Changeset e731b0d in mainline for boot/arch


Ignore:
Timestamp:
2009-08-20T16:58:55Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b9c7425
Parents:
a11099f
Message:

make ppc32 OFW usage on par with sparc64, make appropriate modifications elsewhere

  • introduce ofw_tree_walk_by_device_type() to gather all OFW devices of a given type
  • ppc32 uses canonized OFW tree, mac-io and display devices are detected in kernel (not by the boot loader) by means of device type
  • various busses (PCI, EBUS, etc.) stay sparc64 specific for now
  • boot memcpy() is defined in a common way
  • BALLOC_MAX_SIZE is platform-dependent
  • ppc32 and sparc64 boot loaders cleanup (removal of obsolete stuff, data is not passed by global variables if not necessary, etc.)
  • balloc and OFW tree canonizer have now a provision to support different mapping of the data during boot time and kernel run-time
  • OFW tree canonizer uses balloc_rebase() to store pointers suitable for access during kernel run-time (with potentially different memory mapping than during boot time)
Location:
boot/arch
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/arm32/loader/asm.h

    ra11099f re731b0d  
    4040
    4141
    42 /** Copies cnt bytes from dst to src.
    43  *
    44  * @param dst Destination address.
    45  * @param src Source address.
    46  * @param cnt Count of bytes to be copied.
    47  */
    48 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))
    49 
    50 
    5142/** Called when the CPU is switched on.
    5243 *
  • boot/arch/arm32/loader/main.c

    ra11099f re731b0d  
    4343#include <macros.h>
    4444#include <string.h>
     45#include <memstr.h>
    4546
    4647#include "mm.h"
  • boot/arch/ia64/loader/asm.h

    ra11099f re731b0d  
    3434#include "main.h"
    3535
    36 #define PAGE_WIDTH      14
    37 #define PAGE_SIZE       (1 << PAGE_WIDTH)
     36#define PAGE_WIDTH  14
     37#define PAGE_SIZE   (1 << PAGE_WIDTH)
    3838
    39 #define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
     39#define BALLOC_MAX_SIZE  (128 * 1024)
    4040
    4141extern void halt(void);
    42 /*extern void jump_to_kernel(void *entry, uint64_t cfg, bootinfo_t *bootinfo,
    43         unsigned int bootinfo_size) __attribute__((noreturn));*/
    44 
    4542extern void jump_to_kernel(void *) __attribute__((noreturn));
    4643
  • boot/arch/ia64/loader/main.h

    ra11099f re731b0d  
    3434
    3535
    36 #define CONFIG_INIT_TASKS       32
    37 
    38 
     36#define CONFIG_INIT_TASKS  32
    3937
    4038extern void start(void);
  • boot/arch/mips32/loader/asm.h

    ra11099f re731b0d  
    3333#define PAGE_WIDTH  14
    3434
    35 #define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
    36 
    3735void jump_to_kernel(void *entry, void *bootinfo) __attribute__((noreturn));
    3836
  • boot/arch/mips32/loader/main.c

    ra11099f re731b0d  
    2727 */
    2828
    29 #include "main.h" 
     29#include "main.h"
    3030#include <printf.h>
    3131#include <align.h>
    3232#include <macros.h>
    3333#include <string.h>
     34#include <memstr.h>
    3435#include "msim.h"
    3536#include "asm.h"
  • boot/arch/ppc32/loader/Makefile

    ra11099f re731b0d  
    6262SOURCES = \
    6363        main.c \
    64         ofwarch.c \
    6564        _components.c \
    66         ../../../genarch/ofw.c \
    6765        ../../../generic/printf.c \
    6866        ../../../generic/string.c \
     67        ../../../genarch/balloc.c \
     68        ../../../genarch/ofw.c \
     69        ../../../genarch/ofw_tree.c \
     70        ofwarch.c \
    6971        asm.S \
    7072        boot.S
     
    7375        $(KERNELDIR)/kernel.bin \
    7476        $(USPACEDIR)/srv/ns/ns \
     77        $(USPACEDIR)/app/init/init \
    7578        $(USPACEDIR)/srv/loader/loader \
    76         $(USPACEDIR)/app/init/init \
    7779        $(USPACEDIR)/srv/devmap/devmap \
    7880        $(USPACEDIR)/srv/bd/rd/rd \
     
    99101        $(USPACEDIR)/app/tester/tester \
    100102        $(USPACEDIR)/app/trace/trace \
    101         $(USPACEDIR)/app/klog/klog \
    102         $(USPACEDIR)/app/bdsh/bdsh
     103        $(USPACEDIR)/app/bdsh/bdsh \
     104        $(USPACEDIR)/app/klog/klog
    103105
    104106OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
  • boot/arch/ppc32/loader/_link.ld.in

    ra11099f re731b0d  
    1919[[COMPONENTS]]
    2020        }
     21       
     22        /DISCARD/ : {
     23                *(.comment);
     24                *(.note*);
     25        }
    2126}
  • boot/arch/ppc32/loader/asm.S

    ra11099f re731b0d  
    2929#include "asm.h"
    3030#include "regname.h"
     31#include "ofwarch.h"
    3132
    3233.macro SMC_COHERENCY addr
     
    4546
    4647.macro TLB_FLUSH reg
    47         tlbie \reg
    48         addi \reg, \reg, 0x1000
     48        li \reg, 0
     49        sync
     50       
     51        .rept 64
     52                tlbie \reg
     53                addi \reg, \reg, 0x1000
     54        .endr
     55       
     56        eieio
     57        tlbsync
     58        sync
    4959.endm
    5060
     
    5464.global memcpy
    5565.global jump_to_kernel
     66.global balloc_base
    5667
    5768halt:
     
    6273        addi r6, r3, -4
    6374        addi r4, r4, -4
    64         beq     2f
     75        beq 2f
    6576       
    6677        andi. r0, r6, 3
     
    6980       
    7081        1:
    71        
    72         lwz r7, 4(r4)
    73         lwzu r8, 8(r4)
    74         stw r7, 4(r6)
    75         stwu r8, 8(r6)
    76         bdnz 1b
    77        
    78         andi. r5, r5, 7
     82                lwz r7, 4(r4)
     83                lwzu r8, 8(r4)
     84                stw r7, 4(r6)
     85                stwu r8, 8(r6)
     86                bdnz 1b
     87               
     88                andi. r5, r5, 7
    7989       
    8090        2:
    81        
    82         cmplwi 0, r5, 4
    83         blt 3f
    84        
    85         lwzu r0, 4(r4)
    86         addi r5, r5, -4
    87         stwu r0, 4(r6)
     91                cmplwi 0, r5, 4
     92                blt 3f
     93               
     94                lwzu r0, 4(r4)
     95                addi r5, r5, -4
     96                stwu r0, 4(r6)
    8897       
    8998        3:
    90        
    91         cmpwi 0, r5, 0
    92         beqlr
    93         mtctr r5
    94         addi r4, r4, 3
    95         addi r6, r6, 3
     99                cmpwi 0, r5, 0
     100                beqlr
     101                mtctr r5
     102                addi r4, r4, 3
     103                addi r6, r6, 3
    96104       
    97105        4:
    98        
    99         lbzu r0, 1(r4)
    100         stbu r0, 1(r6)
    101         bdnz 4b
    102         blr
     106                lbzu r0, 1(r4)
     107                stbu r0, 1(r6)
     108                bdnz 4b
     109                blr
    103110       
    104111        5:
    105        
    106         subfic r0, r0, 4
    107         mtctr r0
     112                subfic r0, r0, 4
     113                mtctr r0
    108114       
    109115        6:
    110        
    111         lbz r7, 4(r4)
    112         addi r4, r4, 1
    113         stb r7, 4(r6)
    114         addi r6, r6, 1
    115         bdnz 6b
    116         subf r5, r0, r5
    117         rlwinm. r7, r5, 32-3, 3, 31
    118         beq 2b
    119         mtctr r7
    120         b 1b
    121 
     116                lbz r7, 4(r4)
     117                addi r4, r4, 1
     118                stb r7, 4(r6)
     119                addi r6, r6, 1
     120                bdnz 6b
     121                subf r5, r0, r5
     122                rlwinm. r7, r5, 32-3, 3, 31
     123                beq 2b
     124                mtctr r7
     125                b 1b
    122126
    123127jump_to_kernel:
     
    128132        # r6 = bytes to copy
    129133        # r7 = real_mode (pa)
    130         # r8 = framebuffer (pa)
    131         # r9 = scanline
    132134       
    133135        # disable interrupts
     
    153155        rfi
    154156
     157.align PAGE_WIDTH
     158balloc_base:
     159        .fill BALLOC_MAX_SIZE
     160
    155161.section REALMODE, "ax"
     162
    156163.align PAGE_WIDTH
    157164.global real_mode
    158 
    159165real_mode:
    160166       
    161167        # copy kernel to proper location
    162168        #
     169        # r3 = bootinfo (pa)
     170        # r4 = bootinfo_size
    163171        # r5 = trans (pa)
    164172        # r6 = bytes to copy
    165         # r8 = framebuffer (pa)
    166         # r9 = scanline
    167173       
    168174        li r31, PAGE_SIZE >> 2
     
    343349        # flush TLB
    344350       
    345         li r31, 0
    346         sync
    347        
    348351        TLB_FLUSH r31
    349         TLB_FLUSH r31
    350         TLB_FLUSH r31
    351         TLB_FLUSH r31
    352         TLB_FLUSH r31
    353         TLB_FLUSH r31
    354         TLB_FLUSH r31
    355         TLB_FLUSH r31
    356        
    357         TLB_FLUSH r31
    358         TLB_FLUSH r31
    359         TLB_FLUSH r31
    360         TLB_FLUSH r31
    361         TLB_FLUSH r31
    362         TLB_FLUSH r31
    363         TLB_FLUSH r31
    364         TLB_FLUSH r31
    365        
    366         TLB_FLUSH r31
    367         TLB_FLUSH r31
    368         TLB_FLUSH r31
    369         TLB_FLUSH r31
    370         TLB_FLUSH r31
    371         TLB_FLUSH r31
    372         TLB_FLUSH r31
    373         TLB_FLUSH r31
    374        
    375         TLB_FLUSH r31
    376         TLB_FLUSH r31
    377         TLB_FLUSH r31
    378         TLB_FLUSH r31
    379         TLB_FLUSH r31
    380         TLB_FLUSH r31
    381         TLB_FLUSH r31
    382         TLB_FLUSH r31
    383        
    384         TLB_FLUSH r31
    385         TLB_FLUSH r31
    386         TLB_FLUSH r31
    387         TLB_FLUSH r31
    388         TLB_FLUSH r31
    389         TLB_FLUSH r31
    390         TLB_FLUSH r31
    391         TLB_FLUSH r31
    392        
    393         TLB_FLUSH r31
    394         TLB_FLUSH r31
    395         TLB_FLUSH r31
    396         TLB_FLUSH r31
    397         TLB_FLUSH r31
    398         TLB_FLUSH r31
    399         TLB_FLUSH r31
    400         TLB_FLUSH r31
    401        
    402         TLB_FLUSH r31
    403         TLB_FLUSH r31
    404         TLB_FLUSH r31
    405         TLB_FLUSH r31
    406         TLB_FLUSH r31
    407         TLB_FLUSH r31
    408         TLB_FLUSH r31
    409         TLB_FLUSH r31
    410        
    411         TLB_FLUSH r31
    412         TLB_FLUSH r31
    413         TLB_FLUSH r31
    414         TLB_FLUSH r31
    415         TLB_FLUSH r31
    416         TLB_FLUSH r31
    417         TLB_FLUSH r31
    418         TLB_FLUSH r31
    419        
    420         eieio
    421         tlbsync
    422         sync
    423352       
    424353        # start the kernel
    425354        #
    426         # pc = KERNEL_START_ADDR
     355        # pc = PA2KA(BOOT_OFFSET)
    427356        # r3 = bootinfo (pa)
    428         # sprg0 = KA2PA(KERNEL_START_ADDR)
     357        # sprg0 = BOOT_OFFSET
    429358        # sprg3 = physical memory size
    430359        # sp = 0 (pa)
    431360       
    432         lis r31, KERNEL_START_ADDR@ha
    433         addi r31, r31, KERNEL_START_ADDR@l
    434        
     361        lis r31, PA2KA(BOOT_OFFSET)@ha
     362        addi r31, r31, PA2KA(BOOT_OFFSET)@l
    435363        mtspr srr0, r31
    436364       
    437         subis r31, r31, 0x8000
     365        lis r31, BOOT_OFFSET@ha
     366        addi r31, r31, BOOT_OFFSET@l
    438367        mtsprg0 r31
    439368       
     
    454383.global trans
    455384trans:
    456         .space (TRANS_SIZE * TRANS_ITEM_SIZE)
     385        .rept TRANS_SIZE
     386        .int 0
     387        .endr
  • boot/arch/ppc32/loader/asm.h

    ra11099f re731b0d  
    3030#define BOOT_ppc32_ASM_H_
    3131
    32 #define PAGE_SIZE 4096
    33 #define PAGE_WIDTH 12
     32#define PAGE_WIDTH  12
     33#define PAGE_SIZE   (1 << PAGE_WIDTH)
    3434
    35 #define TRANS_SIZE 1024
    36 #define TRANS_ITEM_SIZE 4
     35#define TRANS_SIZE   1024
     36#define BOOT_OFFSET  0x8000
    3737
    38 #define KERNEL_START_ADDR 0x80008000
     38#define BALLOC_MAX_SIZE  (128 * 1024)
    3939
    4040#ifndef __ASM__
    4141
    42 #define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
     42#include "types.h"
     43#include "main.h"
     44#include "ofwarch.h"
    4345
    44 extern void *trans[TRANS_SIZE];
     46#define PA2KA(x)  (((uintptr_t) (x)) + 0x80000000)
     47
     48extern uint8_t balloc_base[BALLOC_MAX_SIZE];
     49extern uintptr_t trans[TRANS_SIZE];
    4550
    4651extern void halt();
    47 extern void jump_to_kernel(void *bootinfo, unsigned int bootinfo_size, void *trans, unsigned int kernel_size, void *real_mode, void *fb, unsigned int scanline) __attribute__((noreturn));
     52extern void jump_to_kernel(void *bootinfo, unsigned int bootinfo_size,
     53    uintptr_t trans[], unsigned int kernel_size, void *real_mode) __attribute__((noreturn));
    4854extern void real_mode();
     55
     56#else
     57
     58#define PA2KA(x)  ((x) + 0x80000000)
    4959
    5060#endif
  • boot/arch/ppc32/loader/main.c

    ra11099f re731b0d  
    2727 */
    2828
    29 #include "main.h"
    3029#include <printf.h>
    31 #include "asm.h"
    32 #include "_components.h"
    3330#include <ofw.h>
    3431#include <align.h>
    3532#include <macros.h>
    3633#include <string.h>
     34#include "main.h"
     35#include "asm.h"
     36#include "_components.h"
    3737
    38 #define HEAP_GAP 1024000
     38static bootinfo_t bootinfo;
     39static component_t components[COMPONENTS];
     40static char *release = STRING(RELEASE);
    3941
    40 bootinfo_t bootinfo;
     42#ifdef REVISION
     43        static char *revision = ", revision " STRING(REVISION);
     44#else
     45        static char *revision = "";
     46#endif
    4147
     48#ifdef TIMESTAMP
     49        static char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
     50#else
     51        static char *timestamp = "";
     52#endif
     53
     54/** Print version information. */
     55static void version_print(void)
     56{
     57        printf("HelenOS PPC32 Bootloader\nRelease %s%s%s\n"
     58            "Copyright (c) 2006 HelenOS project\n\n",
     59            release, revision, timestamp);
     60}
    4261
    4362static void check_align(const void *addr, const char *desc)
    4463{
    45         if ((unsigned int) addr % PAGE_SIZE != 0) {
     64        if ((uintptr_t) addr % PAGE_SIZE != 0) {
    4665                printf("Error: %s not on page boundary, halting.\n", desc);
    4766                halt();
     
    4968}
    5069
    51 
    52 static void fix_overlap(void *va, void **pa, const char *desc, unsigned int *top)
     70static void check_overlap(const void *pa, const char *desc, const uintptr_t top)
    5371{
    54         if ((unsigned int) *pa + PAGE_SIZE < *top) {
    55                 printf("Warning: %s overlaps kernel physical area\n", desc);
    56                
    57                 void *new_va = (void *) (ALIGN_UP((unsigned int) KERNEL_END + HEAP_GAP, PAGE_SIZE) + *top);
    58                 void *new_pa = (void *) (HEAP_GAP + *top);
    59                 *top += PAGE_SIZE;
    60                
    61                 if (ofw_map(new_pa, new_va, PAGE_SIZE, 0) != 0) {
    62                         printf("Error: Unable to map page aligned memory at %L (physical %L), halting.\n", new_va, new_pa);
    63                         halt();
    64                 }
    65                
    66                 if ((unsigned int) new_pa + PAGE_SIZE < KERNEL_SIZE) {
    67                         printf("Error: %s cannot be relocated, halting.\n", desc);
    68                         halt();
    69                 }
    70                
    71                 printf("Relocating %L -> %L (physical %L -> %L)\n", va, new_va, *pa, new_pa);
    72                 *pa = new_pa;
    73                 memcpy(new_va, va, PAGE_SIZE);
     72        if ((uintptr_t) pa + PAGE_SIZE < top) {
     73                printf("Error: %s overlaps destination physical area\n", desc);
     74                halt();
    7475        }
    75 }
    76 
    77 char *release = STRING(RELEASE);
    78 
    79 #ifdef REVISION
    80         char *revision = ", revision " STRING(REVISION);
    81 #else
    82         char *revision = "";
    83 #endif
    84 
    85 #ifdef TIMESTAMP
    86         char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
    87 #else
    88         char *timestamp = "";
    89 #endif
    90 
    91 /** Print version information. */
    92 static void version_print(void)
    93 {
    94         printf("HelenOS PPC32 Bootloader\nRelease %s%s%s\nCopyright (c) 2006 HelenOS project\n\n", release, revision, timestamp);
    9576}
    9677
     
    9879{
    9980        version_print();
    100        
    101         component_t components[COMPONENTS];
    10281        init_components(components);
    103                
    104         unsigned int i;
    105         for (i = 0; i < COMPONENTS; i++)
    106                 check_align(components[i].start, components[i].name);
    107        
    108         check_align(&real_mode, "bootstrap trampoline");
    109         check_align(&trans, "translation table");
    11082       
    11183        if (!ofw_memmap(&bootinfo.memmap)) {
     
    11991        }
    12092       
    121         if (!ofw_screen(&bootinfo.screen))
    122                 printf("Warning: Unable to get screen properties.\n");
     93        check_align(&real_mode, "bootstrap trampoline");
     94        check_align(trans, "translation table");
     95        check_align(balloc_base, "boot allocations");
    12396       
    124         if (!ofw_macio(&bootinfo.macio))
    125                 printf("Warning: Unable to get macio properties.\n");
     97        unsigned int i;
     98        for (i = 0; i < COMPONENTS; i++)
     99                check_align(components[i].start, components[i].name);
    126100       
    127         printf("Device statistics\n");
     101        void *bootinfo_pa = ofw_translate(&bootinfo);
     102        void *real_mode_pa = ofw_translate(&real_mode);
     103        void *trans_pa = ofw_translate(trans);
     104        void *balloc_base_pa = ofw_translate(balloc_base);
    128105       
    129         if (bootinfo.screen.addr)
    130                 printf(" screen at %L, resolution %dx%d, %d bpp (scanline %d bytes)\n", bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height, bootinfo.screen.bpp, bootinfo.screen.scanline);
    131        
    132         if (bootinfo.macio.addr)
    133                 printf(" macio at %L (size %d bytes)\n", bootinfo.macio.addr, bootinfo.macio.size);
    134        
    135         void *real_mode_pa = ofw_translate(&real_mode);
    136         void *trans_pa = ofw_translate(&trans);
    137         void *bootinfo_pa = ofw_translate(&bootinfo);
    138        
    139         printf("\nMemory statistics (total %d MB)\n", bootinfo.memmap.total >> 20);
     106        printf("Memory statistics (total %d MB)\n", bootinfo.memmap.total >> 20);
    140107        printf(" %L: boot info structure (physical %L)\n", &bootinfo, bootinfo_pa);
    141108        printf(" %L: bootstrap trampoline (physical %L)\n", &real_mode, real_mode_pa);
    142         printf(" %L: translation table (physical %L)\n", &trans, trans_pa);
     109        printf(" %L: translation table (physical %L)\n", trans, trans_pa);
     110        printf(" %L: boot allocations (physical %L)\n", balloc_base, balloc_base_pa);
    143111        for (i = 0; i < COMPONENTS; i++)
    144112                printf(" %L: %s image (size %d bytes)\n", components[i].start, components[i].name, components[i].size);
    145113       
    146         unsigned int top = 0;
     114        uintptr_t top = 0;
    147115        for (i = 0; i < COMPONENTS; i++)
    148116                top += ALIGN_UP(components[i].size, PAGE_SIZE);
     117        top += ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE);
     118       
     119        if (top >= TRANS_SIZE * PAGE_SIZE) {
     120                printf("Error: boot image is too large\n");
     121                halt();
     122        }
     123       
     124        check_overlap(bootinfo_pa, "boot info", top);
     125        check_overlap(real_mode_pa, "bootstrap trampoline", top);
     126        check_overlap(trans_pa, "translation table", top);
    149127       
    150128        unsigned int pages = ALIGN_UP(KERNEL_SIZE, PAGE_SIZE) >> PAGE_WIDTH;
     
    152130        for (i = 0; i < pages; i++) {
    153131                void *pa = ofw_translate(KERNEL_START + (i << PAGE_WIDTH));
    154                 fix_overlap(KERNEL_START + (i << PAGE_WIDTH), &pa, "kernel", &top);
    155                 trans[i] = pa;
     132                check_overlap(pa, "kernel", top);
     133                trans[i] = (uintptr_t) pa;
    156134        }
    157135       
    158136        bootinfo.taskmap.count = 0;
    159137        for (i = 1; i < COMPONENTS; i++) {
     138                if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
     139                        printf("\nSkipping superfluous components.\n");
     140                        break;
     141                }
     142               
    160143                unsigned int component_pages = ALIGN_UP(components[i].size, PAGE_SIZE) >> PAGE_WIDTH;
    161144                unsigned int j;
     
    163146                for (j = 0; j < component_pages; j++) {
    164147                        void *pa = ofw_translate(components[i].start + (j << PAGE_WIDTH));
    165                         fix_overlap(components[i].start + (j << PAGE_WIDTH), &pa, components[i].name, &top);
    166                         trans[pages + j] = pa;
     148                        check_overlap(pa, components[i].name, top);
     149                        trans[pages + j] = (uintptr_t) pa;
    167150                        if (j == 0) {
    168                                 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) (pages << PAGE_WIDTH);
     151                               
     152                                bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) PA2KA(pages << PAGE_WIDTH);
    169153                                bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = components[i].size;
    170154                                strncpy(bootinfo.taskmap.tasks[bootinfo.taskmap.count].name,
    171155                                    components[i].name, BOOTINFO_TASK_NAME_BUFLEN);
    172 
     156                               
    173157                                bootinfo.taskmap.count++;
    174158                        }
     
    178162        }
    179163       
    180         fix_overlap(&real_mode, &real_mode_pa, "bootstrap trampoline", &top);
    181         fix_overlap(&trans, &trans_pa, "translation table", &top);
    182         fix_overlap(&bootinfo, &bootinfo_pa, "boot info", &top);
     164        uintptr_t balloc_kernel_base = PA2KA(pages << PAGE_WIDTH);
     165        unsigned int balloc_pages = ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE) >> PAGE_WIDTH;
     166        for (i = 0; i < balloc_pages; i++) {
     167                void *pa = ofw_translate(balloc_base + (i << PAGE_WIDTH));
     168                check_overlap(pa, "boot allocations", top);
     169                trans[pages + i] = (uintptr_t) pa;
     170        }
     171       
     172        pages += balloc_pages;
     173       
     174        balloc_init(&bootinfo.ballocs, (uintptr_t) balloc_base, balloc_kernel_base);
     175        printf("\nCanonizing OpenFirmware device tree...");
     176        bootinfo.ofw_root = ofw_tree_build();
     177        printf("done.\n");
    183178       
    184179        ofw_setup_palette();
    185180       
    186181        printf("\nBooting the kernel...\n");
    187         jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa, (void *) bootinfo.screen.addr, bootinfo.screen.scanline);
     182        jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa);
    188183}
  • boot/arch/ppc32/loader/main.h

    ra11099f re731b0d  
    3030#define BOOT_ppc32_MAIN_H_
    3131
    32 #include "ofw.h"
     32#include <ofw.h>
     33#include <ofw_tree.h>
     34#include <balloc.h>
     35#include <types.h>
    3336
    34 #define TASKMAP_MAX_RECORDS 32
     37#define TASKMAP_MAX_RECORDS  32
    3538
    3639/** Size of buffer for storing task name in task_t. */
    37 #define BOOTINFO_TASK_NAME_BUFLEN 32
     40#define BOOTINFO_TASK_NAME_BUFLEN  32
    3841
    39 /** Struct holding information about single loaded task. */
    4042typedef struct {
    41         /** Address where the task was placed. */
    4243        void *addr;
    43         /** Size of the task's binary. */
    44         unsigned int size;
    45         /** Task name. */
     44        uint32_t size;
    4645        char name[BOOTINFO_TASK_NAME_BUFLEN];
    4746} task_t;
    4847
    4948typedef struct {
    50         unsigned int count;
     49        uint32_t count;
    5150        task_t tasks[TASKMAP_MAX_RECORDS];
    5251} taskmap_t;
     
    5554        memmap_t memmap;
    5655        taskmap_t taskmap;
    57         screen_t screen;
    58         macio_t macio;
     56        ballocs_t ballocs;
     57        ofw_tree_node_t *ofw_root;
    5958} bootinfo_t;
    6059
     
    6261extern void bootstrap(void);
    6362
    64 extern memmap_t memmap;
    65 
    6663#endif
  • boot/arch/ppc32/loader/ofwarch.c

    ra11099f re731b0d  
    3131#include <printf.h>
    3232
    33 typedef int (* ofw_entry_t)(ofw_args_t *args);
     33typedef int (*ofw_entry_t)(ofw_args_t *args);
    3434
    3535int ofw(ofw_args_t *args)
     
    4949}
    5050
    51 int ofw_macio(macio_t *macio)
    52 {
    53         char device_name[BUF_SIZE];
    54        
    55         if ((ofw_get_property(ofw_aliases, "macio", device_name, sizeof(device_name)) <= 0)
    56             && (ofw_get_property(ofw_aliases, "mac-io", device_name, sizeof(device_name)) <= 0))
    57                 return false;
    58        
    59         phandle device = ofw_find_device(device_name);
    60         if (device == -1)
    61                 return false;
    62        
    63         pci_reg_t pci_reg;
    64         if (ofw_get_property(device, "assigned-addresses", &pci_reg, sizeof(pci_reg)) <= 0)
    65                 return false;
    66        
    67         macio->addr = (void *) pci_reg.addr.addr_lo;
    68         macio->size = pci_reg.size_lo;
    69 
    70         return true;
    71 }
    72 
    7351int ofw_translate_failed(ofw_arg_t flag)
    7452{
     53        /* PearPC returns buggy flag */
    7554        return 0;
    7655}
  • boot/arch/ppc32/loader/ofwarch.h

    ra11099f re731b0d  
    3030#define BOOT_ppc32_OFWARCH_H_
    3131
    32 #define OFW_ADDRESS_CELLS       1
    33 #define OFW_SIZE_CELLS          1
     32#define OFW_ADDRESS_CELLS  1
     33#define OFW_SIZE_CELLS     1
    3434
    3535#endif
  • boot/arch/sparc64/loader/asm.S

    ra11099f re731b0d  
    3131#include <register.h>
    3232
    33 .register       %g2, #scratch
    34 .register       %g3, #scratch
     33.register %g2, #scratch
     34.register %g3, #scratch
    3535
    3636.text
     
    4343        ba %xcc, halt
    4444        nop
     45
     46memcpy:
     47        mov %o0, %o3      ! save dst
     48        add %o1, 7, %g1
     49        and %g1, -8, %g1
     50        cmp %o1, %g1
     51        be,pn %xcc, 3f
     52        add %o0, 7, %g1
     53        mov 0, %g3
    4554       
    46 memcpy:
    47         mov     %o0, %o3                ! save dst
    48         add     %o1, 7, %g1
    49         and     %g1, -8, %g1
    50         cmp     %o1, %g1
    51         be,pn   %xcc, 3f
    52         add     %o0, 7, %g1
    53         mov     0, %g3
    54 0:
    55         brz,pn  %o2, 2f
    56         mov     0, %g2
    57 1:
    58         ldub    [%g3 + %o1], %g1
    59         add     %g2, 1, %g2
    60         cmp     %o2, %g2
    61         stb     %g1, [%g3 + %o0]
    62         bne,pt  %xcc, 1b
    63         mov     %g2, %g3
    64 2:
    65         jmp     %o7 + 8                 ! exit point
    66         mov     %o3, %o0
    67 3:
    68         and     %g1, -8, %g1
    69         cmp     %o0, %g1
    70         bne,pt  %xcc, 0b
    71         mov     0, %g3
    72         srlx    %o2, 3, %g4
    73         brz,pn  %g4, 5f
    74         mov     0, %g5
    75 4:
    76         sllx    %g3, 3, %g2
    77         add     %g5, 1, %g3
    78         ldx     [%o1 + %g2], %g1
    79         mov     %g3, %g5
    80         cmp     %g4, %g3
    81         bne,pt  %xcc, 4b
    82         stx     %g1, [%o0 + %g2]
    83 5:
    84         and     %o2, 7, %o2
    85         brz,pn  %o2, 2b
    86         sllx    %g4, 3, %g1
    87         mov     0, %g2
    88         add     %g1, %o0, %o0
    89         add     %g1, %o1, %g4
    90         mov     0, %g3
    91 6:
    92         ldub    [%g2 + %g4], %g1
    93         stb     %g1, [%g2 + %o0]
    94         add     %g3, 1, %g2
    95         cmp     %o2, %g2
    96         bne,pt  %xcc, 6b
    97         mov     %g2, %g3
    98 
    99         jmp     %o7 + 8                 ! exit point
    100         mov     %o3, %o0
     55        0:
     56                brz,pn %o2, 2f
     57                mov 0, %g2
     58       
     59        1:
     60                ldub [%g3 + %o1], %g1
     61                add %g2, 1, %g2
     62                cmp %o2, %g2
     63                stb %g1, [%g3 + %o0]
     64                bne,pt %xcc, 1b
     65                mov %g2, %g3
     66       
     67        2:
     68                jmp %o7 + 8   ! exit point
     69                mov %o3, %o0
     70       
     71        3:
     72                and %g1, -8, %g1
     73                cmp %o0, %g1
     74                bne,pt %xcc, 0b
     75                mov 0, %g3
     76                srlx %o2, 3, %g4
     77                brz,pn %g4, 5f
     78                mov 0, %g5
     79       
     80        4:
     81                sllx %g3, 3, %g2
     82                add %g5, 1, %g3
     83                ldx [%o1 + %g2], %g1
     84                mov %g3, %g5
     85                cmp %g4, %g3
     86                bne,pt %xcc, 4b
     87                stx %g1, [%o0 + %g2]
     88       
     89        5:
     90                and %o2, 7, %o2
     91                brz,pn %o2, 2b
     92                sllx %g4, 3, %g1
     93                mov 0, %g2
     94                add %g1, %o0, %o0
     95                add %g1, %o1, %g4
     96                mov 0, %g3
     97       
     98        6:
     99                ldub [%g2 + %g4], %g1
     100                stb %g1, [%g2 + %o0]
     101                add %g3, 1, %g2
     102                cmp %o2, %g2
     103                bne,pt %xcc, 6b
     104                mov %g2, %g3
     105       
     106        jmp %o7 + 8   ! exit point
     107        mov %o3, %o0
    101108
    102109jump_to_kernel:
     
    107114         * 3. Flush instruction pipeline.
    108115         */
    109 
     116       
    110117        /*
    111118         * US3 processors have a write-invalidate cache, so explicitly
    112119         * invalidating it is not required. Whether to invalidate I-cache
    113          * or not is decided according to the value of the global
    114          * "subarchitecture" variable (set in the bootstrap).
     120         * or not is decided according to the value of the 5th argument
     121         * (subarchitecture).
    115122         */
    116         set subarchitecture, %g2
    117         ldub [%g2], %g2
    118         cmp %g2, 3
     123        cmp %i4, 3
    119124        be %xcc, 1f
    120125        nop
    121 0:
    122         call icache_flush
    123         nop
    124 1:
    125         membar #StoreStore
     126       
     127        0:
     128                call icache_flush
     129                nop
     130       
     131        1:
     132                membar #StoreStore
    126133       
    127134        /*
    128135         * Flush the instruction pipeline.
    129136         */
    130         flush   %i7
    131 
     137        flush %i7
     138       
    132139        mov %o0, %l1
    133140        mov %o1, %o0
    134141        mov %o2, %o1
    135142        mov %o3, %o2
    136         jmp %l1                         ! jump to kernel
     143        jmp %l1       ! jump to kernel
    137144        nop
    138145
    139 #define ICACHE_SIZE             8192
    140 #define ICACHE_LINE_SIZE        32
    141 #define ICACHE_SET_BIT          (1 << 13)
    142 #define ASI_ICACHE_TAG          0x67
     146#define ICACHE_SIZE       8192
     147#define ICACHE_LINE_SIZE  32
     148#define ICACHE_SET_BIT    (1 << 13)
     149#define ASI_ICACHE_TAG    0x67
    143150
    144151# Flush I-cache
    145152icache_flush:
    146         set     ((ICACHE_SIZE - ICACHE_LINE_SIZE) | ICACHE_SET_BIT), %g1
    147         stxa    %g0, [%g1] ASI_ICACHE_TAG
    148 0:      membar  #Sync
    149         subcc   %g1, ICACHE_LINE_SIZE, %g1
    150         bnz,pt  %xcc, 0b
    151         stxa    %g0, [%g1] ASI_ICACHE_TAG
    152         membar  #Sync
     153        set ((ICACHE_SIZE - ICACHE_LINE_SIZE) | ICACHE_SET_BIT), %g1
     154        stxa %g0, [%g1] ASI_ICACHE_TAG
     155       
     156        0:
     157                membar #Sync
     158                subcc %g1, ICACHE_LINE_SIZE, %g1
     159                bnz,pt %xcc, 0b
     160       
     161        stxa %g0, [%g1] ASI_ICACHE_TAG
     162        membar #Sync
    153163        retl
    154164        ! SF Erratum #51
    155165        nop
     166
    156167.global ofw
    157168ofw:
     
    159170        set ofw_cif, %l0
    160171        ldx [%l0], %l0
    161 
     172       
    162173        rdpr  %pstate, %l1
    163174        and  %l1, ~PSTATE_AM_BIT, %l2
    164175        wrpr  %l2, 0, %pstate
    165    
     176       
    166177        jmpl %l0, %o7
    167178        mov %i0, %o0
    168 
     179       
    169180        wrpr %l1, 0, %pstate
    170 
     181       
    171182        ret
    172183        restore %o0, 0, %o0
  • boot/arch/sparc64/loader/asm.h

    ra11099f re731b0d  
    3434#include "main.h"
    3535
    36 #define PAGE_WIDTH      14
    37 #define PAGE_SIZE       (1 << PAGE_WIDTH)
     36#define PAGE_WIDTH  14
     37#define PAGE_SIZE   (1 << PAGE_WIDTH)
    3838
    39 #define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
     39#define BALLOC_MAX_SIZE  (128 * 1024)
    4040
    4141extern void halt(void);
    4242extern void jump_to_kernel(void *entry, uint64_t cfg, bootinfo_t *bootinfo,
    43         unsigned int bootinfo_size) __attribute__((noreturn));
     43    unsigned int bootinfo_size, uint8_t subarchitecture) __attribute__((noreturn));
    4444
    4545#endif
  • boot/arch/sparc64/loader/main.c

    ra11099f re731b0d  
    11/*
    22 * Copyright (c) 2005 Martin Decky
    3  * Copyright (c) 2006 Jakub Jermar 
     3 * Copyright (c) 2006 Jakub Jermar
    44 * All rights reserved.
    55 *
     
    2828 */
    2929
    30 #include "main.h" 
     30#include "main.h"
    3131#include <printf.h>
    3232#include "asm.h"
     
    3939#include <macros.h>
    4040#include <string.h>
    41 
    42 bootinfo_t bootinfo;
    43 
    44 component_t components[COMPONENTS];
    45 
    46 char *release = STRING(RELEASE);
     41#include <memstr.h>
     42
     43static bootinfo_t bootinfo;
     44static component_t components[COMPONENTS];
     45static char *release = STRING(RELEASE);
    4746
    4847#ifdef REVISION
    49         char *revision = ", revision " STRING(REVISION);
     48        static char *revision = ", revision " STRING(REVISION);
    5049#else
    51         char *revision = "";
     50        static char *revision = "";
    5251#endif
    5352
    5453#ifdef TIMESTAMP
    55         char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
     54        static char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
    5655#else
    57         char *timestamp = "";
     56        static char *timestamp = "";
    5857#endif
    5958
    6059/** UltraSPARC subarchitecture - 1 for US, 3 for US3 */
    61 uint8_t subarchitecture;
     60static uint8_t subarchitecture;
    6261
    6362/**
     
    6564 * MID_SHIFT bits to the right
    6665 */
    67 uint16_t mid_mask;
     66static uint16_t mid_mask;
    6867
    6968/** Print version information. */
     
    7675
    7776/* the lowest ID (read from the VER register) of some US3 CPU model */
    78 #define FIRST_US3_CPU   0x14
     77#define FIRST_US3_CPU  0x14
    7978
    8079/* the greatest ID (read from the VER register) of some US3 CPU model */
    81 #define LAST_US3_CPU    0x19
     80#define LAST_US3_CPU   0x19
    8281
    8382/* UltraSPARC IIIi processor implementation code */
    84 #define US_IIIi_CODE    0x15
     83#define US_IIIi_CODE   0x15
    8584
    8685/**
     
    9190{
    9291        uint64_t v;
    93         asm volatile ("rdpr %%ver, %0\n" : "=r" (v));
     92        asm volatile (
     93                "rdpr %%ver, %0\n"
     94                : "=r" (v)
     95        );
    9496       
    9597        v = (v << 16) >> 48;
     
    103105                subarchitecture = SUBARCH_US;
    104106                mid_mask = (1 << 5) - 1;
    105         } else {
     107        } else
    106108                printf("\nThis CPU is not supported by HelenOS.");
    107         }
    108109}
    109110
     
    113114        void *balloc_base;
    114115        unsigned int top = 0;
    115         int i, j;
    116 
     116        unsigned int i;
     117        unsigned int j;
     118       
    117119        version_print();
    118120       
    119121        detect_subarchitecture();
    120122        init_components(components);
    121 
     123       
    122124        if (!ofw_get_physmem_start(&bootinfo.physmem_start)) {
    123125                printf("Error: unable to get start of physical memory.\n");
    124126                halt();
    125127        }
    126 
     128       
    127129        if (!ofw_memmap(&bootinfo.memmap)) {
    128130                printf("Error: unable to get memory map, halting.\n");
    129131                halt();
    130132        }
    131 
     133       
    132134        if (bootinfo.memmap.total == 0) {
    133135                printf("Error: no memory detected, halting.\n");
    134136                halt();
    135137        }
    136 
     138       
    137139        /*
    138140         * SILO for some reason adds 0x400000 and subtracts
     
    143145                silo_ramdisk_image += bootinfo.physmem_start;
    144146                silo_ramdisk_image -= 0x400000;
    145                 /* Install 1:1 mapping for the ramdisk. */
    146                 if (ofw_map((void *)((uintptr_t) silo_ramdisk_image),
    147                     (void *)((uintptr_t) silo_ramdisk_image),
     147               
     148                /* Install 1:1 mapping for the RAM disk. */
     149                if (ofw_map((void *) ((uintptr_t) silo_ramdisk_image),
     150                    (void *) ((uintptr_t) silo_ramdisk_image),
    148151                    silo_ramdisk_size, -1) != 0) {
    149                         printf("Failed to map ramdisk.\n");
     152                        printf("Failed to map RAM disk.\n");
    150153                        halt();
    151154                }
    152155        }
    153156       
    154         printf("\nSystem info\n");
    155         printf(" memory: %dM starting at %P\n",
     157        printf("\nMemory statistics (total %d MB, starting at %P)\n",
    156158            bootinfo.memmap.total >> 20, bootinfo.physmem_start);
    157 
    158         printf("\nMemory statistics\n");
    159         printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS);
     159        printf(" %P: kernel entry point\n", KERNEL_VIRTUAL_ADDRESS);
    160160        printf(" %P: boot info structure\n", &bootinfo);
    161161       
     
    176176                                break;
    177177                        }
     178                       
    178179                        bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
    179180                            base + top;
     
    187188                top += components[i].size;
    188189        }
    189 
    190         j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */
    191 
     190       
     191        /* Do not consider RAM disk */
     192        j = bootinfo.taskmap.count - 1;
     193       
    192194        if (silo_ramdisk_image) {
    193                 /* Treat the ramdisk as the last bootinfo task. */
     195                /* Treat the RAM disk as the last bootinfo task. */
    194196                if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
    195                         printf("Skipping ramdisk.\n");
     197                        printf("Skipping RAM disk.\n");
    196198                        goto skip_ramdisk;
    197199                }
     200               
    198201                top = ALIGN_UP(top, PAGE_SIZE);
    199202                bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
     
    202205                    silo_ramdisk_size;
    203206                bootinfo.taskmap.count++;
    204                 printf("\nCopying ramdisk...");
     207                printf("\nCopying RAM disk...");
     208               
    205209                /*
    206210                 * Claim and map the whole ramdisk as it may exceed the area
     
    210214                (void) ofw_map(bootinfo.physmem_start + base + top, base + top,
    211215                    silo_ramdisk_size, -1);
    212                 memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image),
     216                memmove(base + top, (void *) ((uintptr_t) silo_ramdisk_image),
    213217                    silo_ramdisk_size);
     218               
    214219                printf("done.\n");
    215220                top += silo_ramdisk_size;
    216221        }
    217222skip_ramdisk:
    218 
     223       
    219224        /*
    220225         * Now we can proceed to copy the components. We do it in reverse order
     
    222227         * with base.
    223228         */
    224         printf("\nCopying bootinfo tasks\n");
     229        printf("\nCopying tasks...");
    225230        for (i = COMPONENTS - 1; i > 0; i--, j--) {
    226                 printf(" %s...", components[i].name);
    227 
     231                printf("%s ", components[i].name);
     232               
    228233                /*
    229234                 * At this point, we claim the physical memory that we are
     
    240245                    bootinfo.taskmap.tasks[j].addr,
    241246                    ALIGN_UP(components[i].size, PAGE_SIZE));
    242                    
    243                 memcpy((void *)bootinfo.taskmap.tasks[j].addr,
     247               
     248                memcpy((void *) bootinfo.taskmap.tasks[j].addr,
    244249                    components[i].start, components[i].size);
    245                 printf("done.\n");
    246         }
    247 
     250               
     251        }
     252        printf(".\n");
     253       
    248254        printf("\nCopying kernel...");
    249255        (void) ofw_claim_phys(bootinfo.physmem_start + base,
     
    251257        memcpy(base, components[0].start, components[0].size);
    252258        printf("done.\n");
    253 
     259       
    254260        /*
    255261         * Claim and map the physical memory for the boot allocator.
     
    261267        (void) ofw_map(bootinfo.physmem_start + balloc_base, balloc_base,
    262268            BALLOC_MAX_SIZE, -1);
    263         balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base);
    264 
     269        balloc_init(&bootinfo.ballocs, (uintptr_t) balloc_base,
     270            (uintptr_t) balloc_base);
     271       
    265272        printf("\nCanonizing OpenFirmware device tree...");
    266273        bootinfo.ofw_root = ofw_tree_build();
    267274        printf("done.\n");
    268 
     275       
    269276#ifdef CONFIG_AP
    270277        printf("\nChecking for secondary processors...");
    271         if (!ofw_cpu())
     278        if (!ofw_cpu(mid_mask, bootinfo.physmem_start))
    272279                printf("Error: unable to get CPU properties\n");
    273280        printf("done.\n");
    274281#endif
    275 
     282       
    276283        ofw_setup_palette();
    277 
     284       
    278285        printf("\nBooting the kernel...\n");
    279286        jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS,
    280287            bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo,
    281             sizeof(bootinfo));
     288            sizeof(bootinfo), subarchitecture);
    282289}
  • boot/arch/sparc64/loader/main.h

    ra11099f re731b0d  
    3535#include <types.h>
    3636
    37 #define KERNEL_VIRTUAL_ADDRESS 0x400000
     37#define KERNEL_VIRTUAL_ADDRESS  0x400000
    3838
    39 #define TASKMAP_MAX_RECORDS 32
     39#define TASKMAP_MAX_RECORDS  32
    4040
    4141/** Size of buffer for storing task name in task_t. */
    42 #define BOOTINFO_TASK_NAME_BUFLEN 32
     42#define BOOTINFO_TASK_NAME_BUFLEN  32
    4343
    44 #define BSP_PROCESSOR   1
    45 #define AP_PROCESSOR    0
     44#define BSP_PROCESSOR  1
     45#define AP_PROCESSOR   0
    4646
    47 #define SUBARCH_US      1
    48 #define SUBARCH_US3     3
     47#define SUBARCH_US   1
     48#define SUBARCH_US3  3
    4949
    5050typedef struct {
     
    7070extern uint32_t silo_ramdisk_size;
    7171
    72 extern bootinfo_t bootinfo;
    73 
    7472extern void start(void);
    7573extern void bootstrap(void);
  • boot/arch/sparc64/loader/ofwarch.c

    ra11099f re731b0d  
    3030/**
    3131 * @file
    32  * @brief       Architecture dependent parts of OpenFirmware interface.
     32 * @brief Architecture dependent parts of OpenFirmware interface.
    3333 */
    3434
     
    4040#include "main.h"
    4141#include "asm.h"
    42 
    43 /* these tho variables will be set by the detect_subarchitecture function */
    44 extern uint8_t subarchitecture;
    45 extern uint16_t mid_mask;
    4642
    4743void write(const char *str, const int len)
     
    6561 * except for the current CPU.
    6662 *
    67  * @param child         The first child of the OFW tree node whose children
    68  *                      represent CPUs to be woken up.
    69  * @param current_mid   MID of the current CPU, the current CPU will
    70  *                      (of course) not be woken up.
    71  * @return              Number of CPUs which have the same parent node as
    72  *                      "child".
     63 * @param child         The first child of the OFW tree node whose children
     64 *                      represent CPUs to be woken up.
     65 * @param current_mid   MID of the current CPU, the current CPU will
     66 *                      (of course) not be woken up.
     67 * @param physmem_start Starting address of the physical memory.
     68 *
     69 * @return Number of CPUs which have the same parent node as
     70 *         "child".
     71 *
    7372 */
    74 static int wake_cpus_in_node(phandle child, uint64_t current_mid)
     73static int wake_cpus_in_node(phandle child, uint64_t current_mid,
     74    uintptr_t physmem_start)
    7575{
    7676        int cpus;
    77         char type_name[BUF_SIZE];
    7877       
    79         for (cpus = 0; child != 0 && child != -1;
     78        for (cpus = 0; (child != 0) && (child != -1);
    8079            child = ofw_get_peer_node(child), cpus++) {
     80                char type_name[BUF_SIZE];
     81               
    8182                if (ofw_get_property(child, "device_type", type_name,
    8283                    sizeof(type_name)) > 0) {
     
    8889                                 * "cpuid" for US-IV
    8990                                 */
    90                                 if (ofw_get_property(
    91                                     child, "upa-portid",
    92                                     &mid, sizeof(mid)) <= 0
    93                                     && ofw_get_property(child, "portid",
    94                                     &mid, sizeof(mid)) <= 0
    95                                     && ofw_get_property(child, "cpuid",
    96                                     &mid, sizeof(mid)) <= 0)
     91                                if ((ofw_get_property(child, "upa-portid", &mid, sizeof(mid)) <= 0)
     92                                    && (ofw_get_property(child, "portid", &mid, sizeof(mid)) <= 0)
     93                                    && (ofw_get_property(child, "cpuid", &mid, sizeof(mid)) <= 0))
    9794                                        continue;
    98                                        
     95                               
    9996                                if (current_mid != mid) {
    10097                                        /*
     
    103100                                        (void) ofw_call("SUNW,start-cpu", 3, 1,
    104101                                            NULL, child, KERNEL_VIRTUAL_ADDRESS,
    105                                             bootinfo.physmem_start |
    106                                             AP_PROCESSOR);
     102                                            physmem_start | AP_PROCESSOR);
    107103                                }
    108104                        }
    109105                }
    110106        }
    111 
     107       
    112108        return cpus;
    113109}
     
    116112 * Finds out the current CPU's MID and wakes up all AP processors.
    117113 */
    118 int ofw_cpu(void)
     114int ofw_cpu(uint16_t mid_mask, uintptr_t physmem_start)
    119115{
    120         int cpus;
    121         phandle node;
    122         phandle subnode;
    123         phandle cpus_parent;
    124         phandle cmp;
    125         char name[BUF_SIZE];
    126 
    127         /* get the current CPU MID */
     116        /* Get the current CPU MID */
    128117        uint64_t current_mid;
    129118       
    130         asm volatile ("ldxa [%1] %2, %0\n"
    131             : "=r" (current_mid)
    132             : "r" (0), "i" (ASI_ICBUS_CONFIG));
     119        asm volatile (
     120                "ldxa [%1] %2, %0\n"
     121                : "=r" (current_mid)
     122                : "r" (0), "i" (ASI_ICBUS_CONFIG)
     123        );
     124       
    133125        current_mid >>= ICBUS_CONFIG_MID_SHIFT;
    134 
    135126        current_mid &= mid_mask;
    136 
    137         /* wake up CPUs */
    138127       
    139         cpus_parent = ofw_find_device("/ssm@0,0");
    140         if (cpus_parent == 0 || cpus_parent == -1) {
     128        /* Wake up the CPUs */
     129       
     130        phandle cpus_parent = ofw_find_device("/ssm@0,0");
     131        if ((cpus_parent == 0) || (cpus_parent == -1))
    141132                cpus_parent = ofw_find_device("/");
    142         }
    143 
    144         node = ofw_get_child_node(cpus_parent);
    145         cpus = wake_cpus_in_node(node, current_mid);
    146         while (node != 0 && node != -1) {
     133       
     134        phandle node = ofw_get_child_node(cpus_parent);
     135        int cpus = wake_cpus_in_node(node, current_mid, physmem_start);
     136        while ((node != 0) && (node != -1)) {
     137                char name[BUF_SIZE];
     138               
    147139                if (ofw_get_property(node, "name", name,
    148                         sizeof(name)) > 0) {
     140                    sizeof(name)) > 0) {
    149141                        if (strcmp(name, "cmp") == 0) {
    150                                 subnode = ofw_get_child_node(node);
     142                                phandle subnode = ofw_get_child_node(node);
    151143                                cpus += wake_cpus_in_node(subnode,
    152                                         current_mid);
     144                                        current_mid, physmem_start);
    153145                        }
    154146                }
     
    157149       
    158150        return cpus;
    159        
    160151}
    161152
    162153/** Get physical memory starting address.
    163154 *
    164  * @param start         Pointer to variable where the physical memory starting
    165  *                      address will be stored.
     155 * @param start Pointer to variable where the physical memory starting
     156 *              address will be stored.
    166157 *
    167  * @return              Non-zero on succes, zero on failure.
     158 * @return Non-zero on succes, zero on failure.
     159 *
    168160 */
    169161int ofw_get_physmem_start(uintptr_t *start)
    170162{
    171163        uint32_t memreg[4];
    172 
    173164        if (ofw_get_property(ofw_memory, "reg", &memreg, sizeof(memreg)) <= 0)
    174165                return 0;
    175 
     166       
    176167        *start = (((uint64_t) memreg[0]) << 32) | memreg[1];
    177168        return 1;
    178169}
    179 
  • boot/arch/sparc64/loader/ofwarch.h

    ra11099f re731b0d  
    3333#include "types.h"
    3434
    35 #define OFW_ADDRESS_CELLS       2
    36 #define OFW_SIZE_CELLS          2
     35#define OFW_ADDRESS_CELLS  2
     36#define OFW_SIZE_CELLS     2
    3737
    38 extern int ofw_cpu(void);
    39 extern int ofw_get_physmem_start(uintptr_t *start); 
     38extern int ofw_cpu(uint16_t mid_mask, uintptr_t physmem_start);
     39extern int ofw_get_physmem_start(uintptr_t *start);
    4040
    4141#endif
Note: See TracChangeset for help on using the changeset viewer.