arm/fdt: Initial reorg of fdt support code
* Makes FDT support code useable by everyone without all of the externs * Further movement to be non-u-boot centic may still happen.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2012-2015, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors
|
||||
* Alexander von Gluck IV, [email protected]
|
||||
*/
|
||||
#ifndef __FDT_SUPPORT_H
|
||||
#define __FDT_SUPPORT_H
|
||||
|
||||
|
||||
#include <KernelExport.h>
|
||||
|
||||
|
||||
void dump_fdt(const void *fdt);
|
||||
status_t fdt_get_cell_count(int32 pathOffset,
|
||||
int32 &addressCells, int32 &sizeCells);
|
||||
|
||||
|
||||
|
||||
#endif /*__FDT_SUPPORT_H*/
|
||||
@@ -1,5 +1,7 @@
|
||||
SubDir HAIKU_TOP src system boot arch arm ;
|
||||
|
||||
UsePrivateHeaders [ FDirName kernel platform $(TARGET_BOOT_PLATFORM) ] ;
|
||||
|
||||
#XXX: should not be needed here
|
||||
UsePrivateHeaders [ FDirName kernel arch $(TARGET_KERNEL_ARCH) board $(TARGET_BOOT_BOARD) ] ;
|
||||
UseLibraryHeaders [ FDirName libfdt ] ;
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "fdt_support.h"
|
||||
|
||||
extern "C" {
|
||||
#include <fdt.h>
|
||||
#include <libfdt.h>
|
||||
@@ -580,43 +582,6 @@ mmu_init_for_kernel(void)
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
fdt_get_cell_count(int32 pathOffset, int32 &addressCells, int32 &sizeCells)
|
||||
{
|
||||
// It would be nice if libfdt provided this.
|
||||
|
||||
// Memory base addresses are provided in 32 or 64 bit flavors
|
||||
// #address-cells and #size-cells matches the number of 32-bit 'cells'
|
||||
// representing the length of the base address and size fields
|
||||
|
||||
// TODO: assert !gFDT || !pathOffset?
|
||||
|
||||
int len;
|
||||
if (!pathOffset) {
|
||||
TRACE(("%s: Invalid FDT pathOffset provided!\n", __func__));
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
const void *prop;
|
||||
prop = fdt_getprop(gFDT, pathOffset, "#address-cells", &len);
|
||||
if (prop && len == sizeof(uint32))
|
||||
addressCells = fdt32_to_cpu(*(uint32_t *)prop);
|
||||
prop = fdt_getprop(gFDT, pathOffset, "#size-cells", &len);
|
||||
if (prop && len == sizeof(uint32))
|
||||
sizeCells = fdt32_to_cpu(*(uint32_t *)prop);
|
||||
|
||||
// NOTE : Cells over 2 is possible in theory...
|
||||
if (addressCells > 2 || sizeCells > 2) {
|
||||
panic("%s: Unsupported FDT cell count detected.\n"
|
||||
"Address Cells: %" B_PRId32 "; Size Cells: %" B_PRId32
|
||||
" (CPU > 64bit?).\n", __func__, addressCells, sizeCells);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
//TODO:move this to generic/ ?
|
||||
static status_t
|
||||
find_physical_memory_ranges(uint64 &total)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
SubDir HAIKU_TOP src system boot platform u-boot ;
|
||||
|
||||
SubDirHdrs $(HAIKU_TOP) headers private kernel boot platform $(TARGET_BOOT_PLATFORM) ;
|
||||
SubDirHdrs $(HAIKU_TOP) headers private kernel platform $(TARGET_BOOT_PLATFORM) ;
|
||||
|
||||
SubDirHdrs $(HAIKU_TOP) src system boot arch $(TARGET_KERNEL_ARCH) ;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "serial.h"
|
||||
#include "console.h"
|
||||
#include "cpu.h"
|
||||
#include "fdt_support.h"
|
||||
#include "mmu.h"
|
||||
#include "smp.h"
|
||||
#include "uimage.h"
|
||||
@@ -59,7 +60,6 @@ extern "C" void _start(void);
|
||||
extern "C" int start_gen(int argc, const char **argv,
|
||||
struct image_header *uimage=NULL, void *fdt=NULL);
|
||||
extern "C" void dump_uimage(struct image_header *image);
|
||||
extern "C" void dump_fdt(const void *fdt);
|
||||
#if defined(__ARM__)
|
||||
extern "C" status_t arch_mailbox_init();
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
SubDir HAIKU_TOP src system kernel platform u-boot ;
|
||||
|
||||
SubDirHdrs $(HAIKU_TOP) headers private kernel platform $(TARGET_BOOT_PLATFORM) ;
|
||||
|
||||
SubDirCcFlags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
||||
SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "fdt_support.h"
|
||||
|
||||
#include <KernelExport.h>
|
||||
#include <ByteOrder.h>
|
||||
#include <ctype.h>
|
||||
@@ -15,13 +17,13 @@ extern "C" {
|
||||
#include <libfdt_env.h>
|
||||
};
|
||||
|
||||
#ifndef _BOOT_MODE
|
||||
/* the bootloader has it in asm code to avoid it ending up in .bss */
|
||||
void *gFDT;
|
||||
//#define TRACE_FDT
|
||||
#ifdef TRACE_FDT
|
||||
# define TRACE(x) dprintf x
|
||||
#else
|
||||
# define TRACE(x) ;
|
||||
#endif
|
||||
|
||||
extern "C" void dump_fdt(const void *fdt);
|
||||
|
||||
//#define FDT_DUMP_NODES
|
||||
//#define FDT_DUMP_PROPS
|
||||
//#define FDT_DUMP_PROP_VALUES
|
||||
@@ -34,6 +36,14 @@ static const char *sTabTab = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef _BOOT_MODE
|
||||
/* the bootloader has it in asm code to avoid it ending up in .bss */
|
||||
void *gFDT;
|
||||
#else
|
||||
extern void *gFDT;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef FDT_DUMP_PROP_VALUES
|
||||
static void dump_hex(const char *data, int32 len, int depth)
|
||||
{
|
||||
@@ -116,3 +126,39 @@ void dump_fdt(const void *fdt)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
fdt_get_cell_count(int32 pathOffset, int32 &addressCells, int32 &sizeCells)
|
||||
{
|
||||
// It would be nice if libfdt provided this.
|
||||
|
||||
// Memory base addresses are provided in 32 or 64 bit flavors
|
||||
// #address-cells and #size-cells matches the number of 32-bit 'cells'
|
||||
// representing the length of the base address and size fields
|
||||
|
||||
// TODO: assert !gFDT || !pathOffset?
|
||||
|
||||
int len;
|
||||
if (!pathOffset) {
|
||||
TRACE(("%s: Invalid FDT pathOffset provided!\n", __func__));
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
const void *prop;
|
||||
prop = fdt_getprop(gFDT, pathOffset, "#address-cells", &len);
|
||||
if (prop && len == sizeof(uint32))
|
||||
addressCells = fdt32_to_cpu(*(uint32_t *)prop);
|
||||
prop = fdt_getprop(gFDT, pathOffset, "#size-cells", &len);
|
||||
if (prop && len == sizeof(uint32))
|
||||
sizeCells = fdt32_to_cpu(*(uint32_t *)prop);
|
||||
|
||||
// NOTE : Cells over 2 is possible in theory...
|
||||
if (addressCells > 2 || sizeCells > 2) {
|
||||
panic("%s: Unsupported FDT cell count detected.\n"
|
||||
"Address Cells: %" B_PRId32 "; Size Cells: %" B_PRId32
|
||||
" (CPU > 64bit?).\n", __func__, addressCells, sizeCells);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user