iPXE
devtree.h
Go to the documentation of this file.
1#ifndef _IPXE_DEVTREE_H
2#define _IPXE_DEVTREE_H
3
4/** @file
5 *
6 * Devicetree bus
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
12#include <ipxe/device.h>
13#include <ipxe/dma.h>
14#include <ipxe/fdt.h>
15
16/** A devicetree device */
17struct dt_device {
18 /** Device name */
19 const char *name;
20 /** Generic device */
21 struct device dev;
22 /** DMA device */
24 /** Driver for this device */
26 /** Driver-private data */
27 void *priv;
28};
29
30/* Define a devicetree device ID */
31#define DT_ID( _name, _desc ) _name
32
33/* Define a devicetree device ID with a corresponding build rule */
34#define DT_ROM( _name, _desc ) DT_ID ( _name, _desc )
35
36/** A devicetree driver */
37struct dt_driver {
38 /** Driver name */
39 const char *name;
40 /** Compatible programming model identifiers */
41 const char **ids;
42 /** Number of compatible programming model identifiers */
43 unsigned int id_count;
44 /**
45 * Probe device
46 *
47 * @v dt Devicetree device
48 * @v offset Starting node offset
49 * @ret rc Return status code
50 */
51 int ( * probe ) ( struct dt_device *dt, unsigned int offset );
52 /**
53 * Remove device
54 *
55 * @v dt Devicetree device
56 */
57 void ( * remove ) ( struct dt_device *dt );
58};
59
60/** Devicetree driver table */
61#define DT_DRIVERS __table ( struct dt_driver, "dt_drivers" )
62
63/** Declare a devicetree driver */
64#define __dt_driver __table_entry ( DT_DRIVERS, 01 )
65
66/**
67 * Set devicetree driver-private data
68 *
69 * @v dt Devicetree device
70 * @v priv Private data
71 */
72static inline void dt_set_drvdata ( struct dt_device *dt, void *priv ) {
73 dt->priv = priv;
74}
75
76/**
77 * Get devicetree driver-private data
78 *
79 * @v dt Devicetree device
80 * @ret priv Private data
81 */
82static inline void * dt_get_drvdata ( struct dt_device *dt ) {
83 return dt->priv;
84}
85
86/**
87 * Get devicetree parent device
88 *
89 * @v dt Devicetree device
90 * @ret parent Parent devicetree device
91 */
92static inline struct dt_device * dt_parent ( struct dt_device *dt ) {
93 return container_of ( dt->dev.parent, struct dt_device, dev );
94}
95
96extern void * dt_ioremap ( struct dt_device *dt, unsigned int offset,
97 unsigned int index, size_t len );
98extern int dt_probe_node ( struct device *parent, unsigned int offset );
99extern void dt_remove_node ( struct device *parent );
100extern int dt_probe_children ( struct dt_device *parent, unsigned int offset );
101extern void dt_remove_children ( struct dt_device *parent );
102
103#endif /* _IPXE_DEVTREE_H */
long index
Definition bigint.h:65
uint16_t offset
Offset to command line.
Definition bzimage.h:3
Device model.
void * dt_ioremap(struct dt_device *dt, unsigned int offset, unsigned int index, size_t len)
Map devicetree range.
Definition devtree.c:52
int dt_probe_node(struct device *parent, unsigned int offset)
Probe devicetree node.
Definition devtree.c:196
static void * dt_get_drvdata(struct dt_device *dt)
Get devicetree driver-private data.
Definition devtree.h:82
void dt_remove_node(struct device *parent)
Remove devicetree node.
Definition devtree.c:241
static void dt_set_drvdata(struct dt_device *dt, void *priv)
Set devicetree driver-private data.
Definition devtree.h:72
int dt_probe_children(struct dt_device *parent, unsigned int offset)
Probe devicetree children.
Definition devtree.c:264
static struct dt_device * dt_parent(struct dt_device *dt)
Get devicetree parent device.
Definition devtree.h:92
void dt_remove_children(struct dt_device *parent)
Remove devicetree children.
Definition devtree.c:310
ring len
Length.
Definition dwmac.h:226
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
Flattened Device Tree.
DMA mappings.
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
A hardware device.
Definition device.h:77
struct device * parent
Bus device.
Definition device.h:89
A DMA-capable device.
Definition dma.h:48
A devicetree device.
Definition devtree.h:17
struct dt_driver * driver
Driver for this device.
Definition devtree.h:25
struct dma_device dma
DMA device.
Definition devtree.h:23
void * priv
Driver-private data.
Definition devtree.h:27
struct device dev
Generic device.
Definition devtree.h:21
const char * name
Device name.
Definition devtree.h:19
A devicetree driver.
Definition devtree.h:37
int(* probe)(struct dt_device *dt, unsigned int offset)
Probe device.
Definition devtree.h:51
const char * name
Driver name.
Definition devtree.h:39
void(* remove)(struct dt_device *dt)
Remove device.
Definition devtree.h:57
unsigned int id_count
Number of compatible programming model identifiers.
Definition devtree.h:43
const char ** ids
Compatible programming model identifiers.
Definition devtree.h:41
static struct tlan_private * priv
Definition tlan.c:225