Changeset 61e90dd in mainline


Ignore:
Timestamp:
2006-09-19T22:42:57Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
16529d5
Parents:
3abe07f5
Message:

Add balloc() (a.k.a boot allocator):

  • balloc() only needs to know how to allocate memory.
  • Memory allocated via balloc() is supposed to be passed to kernel and never freed by boot itself.
  • make kernel aware of boot allocations

More work on OFW device tree:

  • use balloc() to efficiently and safely allocate memory for the canonical copy of the device tree

sparc64 boot:

  • pass OFW device tree root node pointer to kernel
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/sparc64/loader/Makefile

    r3abe07f5 r61e90dd  
    5353        ../../../generic/printf.c \
    5454        ../../../generic/string.c \
     55        ../../../genarch/balloc.c \
    5556        ../../../genarch/ofw.c \
    5657        ../../../genarch/ofw_tree.c \
  • boot/arch/sparc64/loader/main.c

    r3abe07f5 r61e90dd  
    3131#include "asm.h"
    3232#include "_components.h"
     33#include <balloc.h>
    3334#include <ofw.h>
     35#include <ofw_tree.h>
    3436#include "ofwarch.h"
    3537#include <align.h>
     
    8486                printf(" %P: %s image (size %d bytes)\n", components[i].start, components[i].name, components[i].size);
    8587
     88        void * base = (void *) KERNEL_VIRTUAL_ADDRESS;
     89        unsigned int top = 0;
     90
    8691        printf("\nCopying components\n");
    87         unsigned int top = 0;
    8892        bootinfo.taskmap.count = 0;
    8993        for (i = 0; i < COMPONENTS; i++) {
    90                 void * base = (void *) KERNEL_VIRTUAL_ADDRESS;
    91        
    9294                printf(" %s...", components[i].name);
    9395                top = ALIGN_UP(top, PAGE_SIZE);
     
    102104        }
    103105
     106        balloc_init(&bootinfo.ballocs, ALIGN_UP(((uintptr_t) base) + top, PAGE_SIZE));
     107
     108        printf("\nCanonizing OpenFirmware device tree...");
     109        bootinfo.ofw_root = ofw_tree_build();
     110        printf("done.\n");
     111
    104112        printf("\nBooting the kernel...\n");
    105113        jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS, &bootinfo, sizeof(bootinfo));
  • boot/arch/sparc64/loader/main.h

    r3abe07f5 r61e90dd  
    3131
    3232#include <ofw.h>
     33#include <ofw_tree.h>
     34#include <balloc.h>
    3335#include <types.h>
    3436
     
    5557        keyboard_t keyboard;
    5658        cpu_t cpu;
     59        ballocs_t ballocs;
     60        ofw_tree_node_t *ofw_root;
    5761} bootinfo_t;
    5862
  • boot/genarch/ofw_tree.c

    r3abe07f5 r61e90dd  
    3131#include <types.h>
    3232#include <string.h>
     33#include <balloc.h>
    3334
    3435static ofw_tree_node_t *ofw_tree_node_alloc(void)
    3536{
    36         return NULL;
     37        return balloc(sizeof(ofw_tree_node_t), sizeof(ofw_tree_node_t));
    3738}
    3839
    3940static ofw_tree_property_t *ofw_tree_properties_alloc(unsigned count)
    4041{
    41         return NULL;
     42        return balloc(count * sizeof(ofw_tree_property_t), sizeof(ofw_tree_property_t));
    4243}
    4344
    4445static void * ofw_tree_space_alloc(size_t size)
    4546{
    46         return NULL;
     47        return balloc(size, size);
    4748}
    4849
  • boot/genarch/ofw_tree.h

    r3abe07f5 r61e90dd  
    3838typedef struct ofw_tree_property ofw_tree_property_t;
    3939
     40/** Memory representation of OpenFirmware device tree node. */
    4041struct ofw_tree_node {
    4142        ofw_tree_node_t *parent;
     
    4344        ofw_tree_node_t *child;
    4445
    45         unsigned properties;
     46        unsigned properties;                    /**< Number of properties. */
    4647        ofw_tree_property_t *property;
    4748};
    4849
     50/** Memory representation of OpenFirmware device tree node property. */
    4951struct ofw_tree_property {
    5052        char name[OFW_TREE_PROPERTY_MAX_NAMELEN];
  • kernel/arch/sparc64/include/boot/boot.h

    r3abe07f5 r61e90dd  
    3636#define KERN_sparc64_BOOT_H_
    3737
    38 
    3938#define VMA                     0x400000
    4039#define LMA                     VMA
     
    4342#ifndef __LINKER__
    4443
     44#include <config.h>
    4545#include <arch/types.h>
    4646#include <typedefs.h>
     47#include <genarch/ofw/ofw_tree.h>
    4748
    4849#define TASKMAP_MAX_RECORDS     32
     
    8788} processor_t;
    8889
     90/** Bootinfo structure.
     91 *
     92 * Must be in sync with bootinfo structure used by the boot loader.
     93 */
    8994typedef struct {
    9095        taskmap_t taskmap;
     
    9398        keyboard_t keyboard;
    9499        processor_t processor;
     100        ballocs_t ballocs;
     101        ofw_tree_node_t *ofw_root;
    95102} bootinfo_t;
    96103
  • kernel/arch/sparc64/src/sparc64.c

    r3abe07f5 r61e90dd  
    5252void arch_pre_main(void)
    5353{
    54         /* Setup usermode */
     54        /* Copy init task info. */
    5555        init.cnt = bootinfo.taskmap.count;
    5656       
     
    6161                init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
    6262        }
     63       
     64        /* Copy boot allocations info. */
     65        ballocs.base = bootinfo.ballocs.base;
     66        ballocs.size = bootinfo.ballocs.size;
    6367}
    6468
  • kernel/genarch/Makefile.inc

    r3abe07f5 r61e90dd  
    8888                genarch/src/kbd/scanc_sun.c
    8989endif
     90
     91
     92## OpenFirmware Device Tree
     93ifeq ($(CONFIG_OFW_TREE), y)
     94        GENARCH_SOURCES += \
     95                genarch/src/ofw/ofw_tree,c
     96endif
  • kernel/generic/include/config.h

    r3abe07f5 r61e90dd  
    5656} init_t;
    5757
     58/** Boot allocations.
     59 *
     60 * Allocatations made by the boot that are meant to be used by the kernel
     61 * are all recorded in the ballocs_t type.
     62 */
     63typedef struct {
     64        uintptr_t base;
     65        size_t size;
     66} ballocs_t;
     67
    5868typedef struct {
    5969        count_t cpu_count;              /**< Number of processors detected. */
     
    7080extern config_t config;
    7181extern init_t init;
     82extern ballocs_t ballocs;
    7283
    7384#endif
  • kernel/generic/src/main/main.c

    r3abe07f5 r61e90dd  
    9595};
    9696
     97/** Boot allocations. */
     98ballocs_t ballocs = {
     99        .base = NULL,
     100        .size = 0
     101};
     102
    97103context_t ctx;
    98104
     
    106112size_t hardcoded_kdata_size = 0;        /**< Size of the kernel data in bytes. */
    107113
    108 uintptr_t stack_safe = 0;       /**< Lowest safe stack virtual address */
     114uintptr_t stack_safe = 0;               /**< Lowest safe stack virtual address */
    109115
    110116void main_bsp(void);
     
    152158                if (PA_overlaps(config.stack_base, config.stack_size, init.tasks[i].addr, init.tasks[i].size))
    153159                        config.stack_base = ALIGN_UP(init.tasks[i].addr + init.tasks[i].size, config.stack_size);
     160        }
     161
     162        /* Avoid placing stack on top of boot allocations. */
     163        if (ballocs.size) {
     164                if (PA_overlaps(config.stack_base, config.stack_size, ballocs.base, ballocs.size))
     165                        config.stack_base = ALIGN_UP(ballocs.base + ballocs.size, PAGE_SIZE);
    154166        }
    155167       
  • kernel/generic/src/mm/frame.c

    r3abe07f5 r61e90dd  
    10781078                        frame_mark_unavailable(ADDR2PFN(KA2PA(init.tasks[i].addr)), SIZE2FRAMES(init.tasks[i].size));
    10791079
     1080                if (ballocs.size)
     1081                        frame_mark_unavailable(ADDR2PFN(KA2PA(ballocs.base)), SIZE2FRAMES(ballocs.size));
     1082
    10801083                /* Black list first frame, as allocating NULL would
    10811084                 * fail in some places */
Note: See TracChangeset for help on using the changeset viewer.