arch/powerpc/boot/libfdt-wrapper.c
Source file repositories/reference/linux-study-clean/arch/powerpc/boot/libfdt-wrapper.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/boot/libfdt-wrapper.c- Extension
.c- Size
- 4520 bytes
- Lines
- 186
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
Dependency Surface
stddef.hstdio.hpage.hlibfdt.hops.h
Detected Declarations
function expand_buffunction fdt_wrapper_getpropfunction fdt_wrapper_setpropfunction fdt_wrapper_del_nodefunction fdt_wrapper_finalizefunction fdt_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* This file does the necessary interface mapping between the bootwrapper
* device tree operations and the interface provided by shared source
* files flatdevicetree.[ch].
*
* Copyright 2007 David Gibson, IBM Corporation.
*/
#include <stddef.h>
#include <stdio.h>
#include <page.h>
#include <libfdt.h>
#include "ops.h"
#define DEBUG 0
#define BAD_ERROR(err) (((err) < 0) \
&& ((err) != -FDT_ERR_NOTFOUND) \
&& ((err) != -FDT_ERR_EXISTS))
#define check_err(err) \
({ \
if (BAD_ERROR(err) || ((err < 0) && DEBUG)) \
printf("%s():%d %s\n\r", __func__, __LINE__, \
fdt_strerror(err)); \
if (BAD_ERROR(err)) \
exit(); \
(err < 0) ? -1 : 0; \
})
#define offset_devp(off) \
({ \
unsigned long _offset = (off); \
check_err(_offset) ? NULL : (void *)(_offset+1); \
})
#define devp_offset_find(devp) (((unsigned long)(devp))-1)
#define devp_offset(devp) (devp ? ((unsigned long)(devp))-1 : 0)
static void *fdt;
static void *buf; /* = NULL */
#define EXPAND_GRANULARITY 1024
static void expand_buf(int minexpand)
{
int size = fdt_totalsize(fdt);
int rc;
size = _ALIGN(size + minexpand, EXPAND_GRANULARITY);
buf = platform_ops.realloc(buf, size);
if (!buf)
fatal("Couldn't find %d bytes to expand device tree\n\r", size);
rc = fdt_open_into(fdt, buf, size);
if (rc != 0)
fatal("Couldn't expand fdt into new buffer: %s\n\r",
fdt_strerror(rc));
fdt = buf;
}
static void *fdt_wrapper_finddevice(const char *path)
{
return offset_devp(fdt_path_offset(fdt, path));
}
static int fdt_wrapper_getprop(const void *devp, const char *name,
void *buf, const int buflen)
{
const void *p;
int len;
p = fdt_getprop(fdt, devp_offset(devp), name, &len);
if (!p)
return check_err(len);
memcpy(buf, p, min(len, buflen));
return len;
}
static int fdt_wrapper_setprop(const void *devp, const char *name,
const void *buf, const int len)
{
int rc;
rc = fdt_setprop(fdt, devp_offset(devp), name, buf, len);
if (rc == -FDT_ERR_NOSPACE) {
expand_buf(len + 16);
rc = fdt_setprop(fdt, devp_offset(devp), name, buf, len);
}
Annotation
- Immediate include surface: `stddef.h`, `stdio.h`, `page.h`, `libfdt.h`, `ops.h`.
- Detected declarations: `function expand_buf`, `function fdt_wrapper_getprop`, `function fdt_wrapper_setprop`, `function fdt_wrapper_del_node`, `function fdt_wrapper_finalize`, `function fdt_init`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.