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