qemu/include/hw/fdt_generic.h
<<
>>
Prefs
   1/*
   2 * Tables of FDT device models and their init functions. Keyed by compatibility
   3 * strings, device instance names.
   4 */
   5
   6#ifndef FDT_GENERIC_H
   7#define FDT_GENERIC_H
   8
   9#include "qemu-common.h"
  10#include "hw/irq.h"
  11#include "sysemu/device_tree.h"
  12#include "qemu/coroutine.h"
  13
  14typedef struct FDTDevOpaque {
  15    char *node_path;
  16    void *opaque;
  17} FDTDevOpaque;
  18
  19typedef struct FDTIRQConnection {
  20    DeviceState *dev;
  21    const char *name;
  22    int i;
  23    bool (*merge_fn)(bool *, int);
  24    qemu_irq irq;
  25    char *sink_info; /* Debug only */
  26    void *next;
  27} FDTIRQConnection;
  28
  29typedef struct FDTMachineInfo {
  30    /* the fdt blob */
  31    void *fdt;
  32    /* irq descriptors for top level int controller */
  33    qemu_irq *irq_base;
  34    /* per-device specific opaques */
  35    FDTDevOpaque *dev_opaques;
  36    /* recheck coroutine queue */
  37    CoQueue *cq;
  38    /* list of all IRQ connections */
  39    FDTIRQConnection *irqs;
  40} FDTMachineInfo;
  41
  42/* create a new FDTMachineInfo. The client is responsible for setting irq_base.
  43 * the mutex fdt_mutex is locked on return. Client must call
  44 * fdt_init_destroy_fdti to cleanup
  45 */
  46
  47FDTMachineInfo *fdt_init_new_fdti(void *fdt);
  48void fdt_init_destroy_fdti(FDTMachineInfo *fdti);
  49
  50typedef int (*FDTInitFn)(char *, FDTMachineInfo *, void *);
  51
  52/* associate a FDTInitFn with a FDT compatibility */
  53
  54void add_to_compat_table(FDTInitFn, const char *, void *);
  55
  56/* try and find a device model for a particular compatibility. If found,
  57 * the FDTInitFn associated with the compat will be called and 0 will
  58 * be returned. Returns non-zero on not found or error
  59 */
  60
  61int fdt_init_compat(char *, FDTMachineInfo *, const char *);
  62
  63/* same as above, but associates with a FDT node name (rather than compat) */
  64
  65void add_to_inst_bind_table(FDTInitFn, const char *, void *);
  66int fdt_init_inst_bind(char *, FDTMachineInfo *, const char *);
  67
  68void dump_compat_table(void);
  69void dump_inst_bind_table(void);
  70
  71/* Called from FDTInitFn's to inform the framework that a dependency is
  72 * unresolved and the calling context needs to wait for another device to
  73 * instantiate first. The calling thread will suspend until a change in state
  74 * in the argument fdt machine is detected.
  75 */
  76
  77void fdt_init_yield(FDTMachineInfo *);
  78
  79/* set, check and get per device opaques. Keyed by fdt node_paths */
  80
  81void fdt_init_set_opaque(FDTMachineInfo *fdti, char *node_path, void *opaque);
  82int fdt_init_has_opaque(FDTMachineInfo *fdti, char *node_path);
  83void *fdt_init_get_opaque(FDTMachineInfo *fdti, char *node_path);
  84
  85/* statically register a FDTInitFn as being associate with a compatibility */
  86
  87#define fdt_register_compatibility_opaque(function, compat, n, opaque) \
  88static void __attribute__((constructor)) \
  89function ## n ## _register_imp(void) { \
  90    add_to_compat_table(function, compat, opaque); \
  91}
  92
  93#define fdt_register_compatibility_n(function, compat, n) \
  94fdt_register_compatibility_opaque(function, compat, n, NULL)
  95
  96#define fdt_register_compatibility(function, compat) \
  97fdt_register_compatibility_n(function, compat, 0)
  98
  99#define fdt_register_instance_opaque(function, inst, n, opaque) \
 100static void __attribute__((constructor)) \
 101function ## n ## _register_imp(void) { \
 102    add_to_inst_bind_table(function, inst, opaque); \
 103}
 104
 105#define fdt_register_instance_n(function, inst, n) \
 106fdt_register_instance_opaque(function, inst, n, NULL)
 107
 108#define fdt_register_instance(function, inst) \
 109fdt_register_instance_n(function, inst, 0)
 110
 111#endif /* FDT_GENERIC_H */
 112