RTEMS CPU Kit with SuperCore  4.11.3
drvmgr.h
Go to the documentation of this file.
1 /* Driver Manager Interface.
2  *
3  * COPYRIGHT (c) 2009 Cobham Gaisler AB.
4  *
5  * The license and distribution terms for this file may be
6  * found in the file LICENSE in this distribution or at
7  * http://www.rtems.org/license/LICENSE.
8  */
9 
10 #ifndef _DRIVER_MANAGER_H_
11 #define _DRIVER_MANAGER_H_
12 
13 #include <rtems.h>
14 #include <drvmgr/drvmgr_list.h>
15 #include <stdint.h>
16 #include <rtems/score/basedefs.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /*** Configure Driver manager ***/
23 
24 /* Define the number of initialization levels of device drivers */
25 #define DRVMGR_LEVEL_MAX 4
26 
27 /* Default to use semahpores for protection. Initialization works without
28  * locks and after initialization too if devices are not removed.
29  */
30 #ifndef DRVMGR_USE_LOCKS
31 #define DRVMGR_USE_LOCKS 1
32 #endif
33 
34 struct drvmgr_dev; /* Device */
35 struct drvmgr_bus; /* Bus */
36 struct drvmgr_drv; /* Driver */
37 
38 /*** List Interface shortcuts ***/
39 #define BUS_LIST_HEAD(list) LIST_HEAD(list, struct drvmgr_bus)
40 #define BUS_LIST_TAIL(list) LIST_TAIL(list, struct drvmgr_bus)
41 #define DEV_LIST_HEAD(list) LIST_HEAD(list, struct drvmgr_dev)
42 #define DEV_LIST_TAIL(list) LIST_TAIL(list, struct drvmgr_dev)
43 #define DRV_LIST_HEAD(list) LIST_HEAD(list, struct drvmgr_drv)
44 #define DRV_LIST_TAIL(list) LIST_TAIL(list, struct drvmgr_drv)
45 
46 /*** Bus indentification ***/
47 #define DRVMGR_BUS_TYPE_NONE 0 /* Not a valid bus */
48 #define DRVMGR_BUS_TYPE_ROOT 1 /* Hard coded bus */
49 #define DRVMGR_BUS_TYPE_PCI 2 /* PCI bus */
50 #define DRVMGR_BUS_TYPE_AMBAPP 3 /* AMBA Plug & Play bus */
51 #define DRVMGR_BUS_TYPE_LEON2_AMBA 4 /* LEON2 hardcoded bus */
52 #define DRVMGR_BUS_TYPE_AMBAPP_DIST 5 /* Distibuted AMBA Plug & Play bus accessed using a communication interface */
53 #define DRVMGR_BUS_TYPE_SPW_RMAP 6 /* SpaceWire Network bus */
54 #define DRVMGR_BUS_TYPE_AMBAPP_RMAP 7 /* SpaceWire RMAP accessed AMBA Plug & Play bus */
55 
56 enum {
57  DRVMGR_OBJ_NONE = 0,
58  DRVMGR_OBJ_DRV = 1,
59  DRVMGR_OBJ_BUS = 2,
60  DRVMGR_OBJ_DEV = 3,
61 };
62 
63 /*** Driver indentification ***
64  *
65  * 64-bit identification integer definition
66  * * Bus ID 8-bit [7..0]
67  * * Reserved 8-bit field [63..56]
68  * * Device ID specific for bus type 48-bit [55..8] (Different buses have
69  * different unique identifications for hardware/driver.)
70  *
71  * ID Rules
72  * * A root bus driver must always have device ID set to 0. There can only by
73  * one root bus driver for a certain bus type.
74  * * A Driver ID must identify a unique hardware core
75  *
76  */
77 
78 /* Bus ID Mask */
79 #define DRIVER_ID_BUS_MASK 0x00000000000000FFULL
80 
81 /* Reserved Mask for future use */
82 #define DRIVER_ID_RSV_MASK 0xFF00000000000000ULL
83 
84 /* Reserved Mask for future use */
85 #define DRIVER_ID_DEV_MASK 0x00FFFFFFFFFFFF00ULL
86 
87 /* Set Bus ID Mask. */
88 #define DRIVER_ID(busid, devid) ((unsigned long long) \
89  ((((unsigned long long)(devid) << 8) & DRIVER_ID_DEV_MASK) | \
90  ((unsigned long long)(busid) & DRIVER_ID_BUS_MASK)))
91 
92 /* Get IDs */
93 #define DRIVER_BUSID_GET(id) ((unsigned long long)(id) & DRIVER_ID_BUS_MASK)
94 #define DRIVER_DEVID_GET(id) (((unsigned long long)(id) & DRIVER_ID_DEV_MASK) >> 8)
95 
96 #define DRIVER_ROOTBUS_ID(bus_type) DRIVER_ID(bus_type, 0)
97 
98 /*** Root Bus drivers ***/
99 
100 /* Generic Hard coded Root bus: Driver ID */
101 #define DRIVER_ROOT_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_ROOT)
102 
103 /* PCI Plug & Play bus: Driver ID */
104 #define DRIVER_PCIBUS_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_PCI)
105 
106 /* AMBA Plug & Play bus: Driver ID */
107 #define DRIVER_GRLIB_AMBAPP_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_AMBAPP)
108 
109 /* AMBA Hard coded bus: Driver ID */
110 #define DRIVER_LEON2_AMBA_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_LEON2_AMBA)
111 
112 /* Distributed AMBA Plug & Play bus: Driver ID */
113 #define DRIVER_AMBAPP_DIST_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_AMBAPP_DIST)
114 
120 struct drvmgr_bus_params {
121  char *dev_prefix;
122 };
123 
124 /* Interrupt Service Routine (ISR) */
125 typedef void (*drvmgr_isr)(void *arg);
126 
128 struct drvmgr_bus_ops {
129  /* Functions used internally within driver manager */
130  int (*init[DRVMGR_LEVEL_MAX])(struct drvmgr_bus *);
131  int (*remove)(struct drvmgr_bus *);
132  int (*unite)(struct drvmgr_drv *, struct drvmgr_dev *);
134  /* Functions called indirectly from drivers */
135  int (*int_register)(struct drvmgr_dev *, int index, const char *info, drvmgr_isr isr, void *arg);
136  int (*int_unregister)(struct drvmgr_dev *, int index, drvmgr_isr isr, void *arg);
137  int (*int_clear)(struct drvmgr_dev *, int index);
138  int (*int_mask)(struct drvmgr_dev *, int index);
139  int (*int_unmask)(struct drvmgr_dev *, int index);
140 
141  /* Get Parameters */
142  int (*get_params)(struct drvmgr_dev *, struct drvmgr_bus_params *);
143  /* Get Frequency of Bus */
144  int (*get_freq)(struct drvmgr_dev*, int, unsigned int*);
148  void (*get_info_dev)(struct drvmgr_dev *,
149  void (*print)(void *p, char *str), void *p);
150 };
151 #define BUS_OPS_NUM (sizeof(struct drvmgr_bus_ops)/sizeof(void (*)(void)))
152 
153 struct drvmgr_func {
154  int funcid;
155  void *func;
156 };
157 #define DRVMGR_FUNC(_ID_, _FUNC_) {(int)(_ID_), (void *)(_FUNC_)}
158 #define DRVMGR_FUNC_END {0, NULL}
159 
160 /*** Resource definitions ***
161  *
162  * Overview of structures:
163  * All bus resources entries (_bus_res) are linked together per bus
164  * (bus_info->reslist). One bus resource entry has a pointer to an array of
165  * driver resources (_drv_res). One driver resouces is made out of an array
166  * of keys (drvmgr_key). All keys belongs to the same driver and harwdare
167  * device. Each key has a Name, Type ID and Data interpreted differently
168  * depending on the Type ID (union drvmgr_key_value).
169  *
170  */
171 
172 /* Key Data Types */
173 enum drvmgr_kt {
174  DRVMGR_KT_ANY = -1,
175  DRVMGR_KT_NONE = 0,
176  DRVMGR_KT_INT = 1,
177  DRVMGR_KT_STRING = 2,
178  DRVMGR_KT_POINTER = 3,
179 };
180 
181 #define DRVMGR_KEY_EMPTY {NULL, DRVMGR_KT_NONE, {0}}
182 #define DRVMGR_RES_EMPTY {0, 0, NULL}
183 #define MMAP_EMPTY {0, 0, 0}
184 
186 union drvmgr_key_value {
187  unsigned int i;
188  char *str;
189  void *ptr;
190 };
191 
192 /* One key. One Value. Holding information relevant to the driver. */
193 struct drvmgr_key {
194  char *key_name; /* Name of key */
195  enum drvmgr_kt key_type; /* How to interpret key_value */
196  union drvmgr_key_value key_value; /* The value or pointer to value */
197 };
198 
202 struct drvmgr_drv_res {
203  uint64_t drv_id;
204  int minor_bus;
205  struct drvmgr_key *keys;
206 };
207 
209 struct drvmgr_bus_res {
211  struct drvmgr_drv_res resource[];
212 };
213 
220 struct drvmgr_map_entry {
221  char *name;
222  unsigned int size;
223  char *from_adr;
225  char *to_adr;
227 };
228 #define DRVMGR_TRANSLATE_ONE2ONE NULL
229 #define DRVMGR_TRANSLATE_NO_BRIDGE ((void *)1) /* No bridge, error */
230 
232 struct drvmgr_bus {
233  int obj_type;
234  unsigned char bus_type;
235  unsigned char depth;
236  struct drvmgr_bus *next;
237  struct drvmgr_dev *dev;
238  void *priv;
239  struct drvmgr_dev *children;
240  struct drvmgr_bus_ops *ops;
241  struct drvmgr_func *funcs;
242  int dev_cnt;
243  struct drvmgr_bus_res *reslist;
244  struct drvmgr_map_entry *maps_up;
245  struct drvmgr_map_entry *maps_down;
247  /* Bus status */
248  int level;
249  int state;
250  int error;
251 };
252 
253 /* States of a bus */
254 #define BUS_STATE_INIT_FAILED 0x00000001 /* Initialization Failed */
255 #define BUS_STATE_LIST_INACTIVE 0x00001000 /* In inactive bus list */
256 #define BUS_STATE_DEPEND_FAILED 0x00000004 /* Device init failed */
257 
258 /* States of a device */
259 #define DEV_STATE_INIT_FAILED 0x00000001 /* Initialization Failed */
260 #define DEV_STATE_INIT_DONE 0x00000002 /* All init levels completed */
261 #define DEV_STATE_DEPEND_FAILED 0x00000004 /* Parent Bus init failed */
262 #define DEV_STATE_UNITED 0x00000100 /* Device United with Device Driver */
263 #define DEV_STATE_REMOVED 0x00000200 /* Device has been removed (unregistered) */
264 #define DEV_STATE_IGNORED 0x00000400 /* Device was ignored according to user's request, the device
265  * was never reported to it's driver (as expected).
266  */
267 #define DEV_STATE_LIST_INACTIVE 0x00001000 /* In inactive device list */
268 
270 struct drvmgr_dev {
271  int obj_type;
272  struct drvmgr_dev *next;
276  struct drvmgr_drv *drv;
277  struct drvmgr_bus *parent;
278  short minor_drv;
279  short minor_bus;
280  char *name;
281  void *priv;
282  void *businfo;
283  struct drvmgr_bus *bus;
285  /* Device Status */
286  unsigned int state;
287  int level;
288  int error;
289 };
290 
292 struct drvmgr_drv_ops {
293  int (*init[DRVMGR_LEVEL_MAX])(struct drvmgr_dev *);
294  int (*remove)(struct drvmgr_dev *);
295  int (*info)(struct drvmgr_dev *, void (*print)(void *p, char *str), void *p, int, char *argv[]);
296 };
297 #define DRVMGR_OPS_NUM(x) (sizeof(x)/sizeof(void (*)(void)))
298 
300 struct drvmgr_drv {
301  int obj_type;
302  struct drvmgr_drv *next;
303  struct drvmgr_dev *dev;
305  uint64_t drv_id;
306  char *name;
307  int bus_type;
308  struct drvmgr_drv_ops *ops;
309  struct drvmgr_func *funcs;
310  unsigned int dev_cnt;
311  unsigned int dev_priv_size;
312 };
313 
318 typedef void (*drvmgr_drv_reg_func)(void);
320 /*** DRIVER | DEVICE | BUS FUNCTIONS ***/
321 
322 /* Return Codes */
323 enum {
324  DRVMGR_OK = 0, /* Sucess */
325  DRVMGR_NOMEM = 1, /* Memory allocation error */
326  DRVMGR_EIO = 2, /* I/O error */
327  DRVMGR_EINVAL = 3, /* Invalid parameter */
328  DRVMGR_ENOSYS = 4,
329  DRVMGR_TIMEDOUT = 5, /* Operation timeout error */
330  DRVMGR_EBUSY = 6,
331  DRVMGR_ENORES = 7, /* Not enough resources */
332  DRVMGR_FAIL = -1 /* Unspecified failure */
333 };
334 
339 extern void _DRV_Manager_initialization(void);
340 
346 extern void _DRV_Manager_init_level(int level);
347 
352 extern void bsp_driver_level_hook(int level);
353 
359 extern int drvmgr_init(void);
360 
361 /* Take registered buses and devices into the correct init level,
362  * this function is called from _init_level() so normally
363  * we don't need to call it directly.
364  */
365 extern void drvmgr_init_update(void);
366 
368 extern int drvmgr_root_drv_register(struct drvmgr_drv *drv);
369 
371 extern int drvmgr_drv_register(struct drvmgr_drv *drv);
372 
374 extern int drvmgr_dev_register(struct drvmgr_dev *dev);
375 
386 extern int drvmgr_dev_unregister(struct drvmgr_dev *dev);
387 
389 extern int drvmgr_bus_register(struct drvmgr_bus *bus);
390 
392 extern int drvmgr_bus_unregister(struct drvmgr_bus *bus);
393 
399 extern int drvmgr_children_unregister(struct drvmgr_bus *bus);
400 
401 /* Separate a device from the driver it has been united with */
402 extern int drvmgr_dev_drv_separate(struct drvmgr_dev *dev);
403 
410 extern int drvmgr_alloc_dev(struct drvmgr_dev **pdev, int extra);
411 
418 extern int drvmgr_alloc_bus(struct drvmgr_bus **pbus, int extra);
419 
420 /*** DRIVER RESOURCE FUNCTIONS ***/
421 
428 extern void drvmgr_bus_res_add(struct drvmgr_bus *bus,
429  struct drvmgr_bus_res *bres);
430 
437 extern int drvmgr_keys_get(struct drvmgr_dev *dev, struct drvmgr_key **keys);
438 
445 extern struct drvmgr_key *drvmgr_key_get(struct drvmgr_key *keys, char *key_name);
446 
460  struct drvmgr_key *keys,
461  char *key_name,
462  enum drvmgr_kt key_type);
463 
477  struct drvmgr_dev *dev,
478  char *key_name,
479  enum drvmgr_kt key_type);
480 
481 /*** DRIVER INTERACE USED TO REQUEST INFORMATION/SERVICES FROM BUS DRIVER ***/
482 
485  struct drvmgr_dev *dev)
486 {
487  if (dev)
488  return dev->parent;
489  else
490  return NULL;
491 }
492 
495 {
496  if (dev)
497  return dev->drv;
498  else
499  return NULL;
500 }
501 
514 #define DRVMGR_FED_BF 1 /* Breadth-first search */
515 #define DRVMGR_FED_DF 0 /* Depth first search */
516 extern int drvmgr_for_each_dev(
517  int (*func)(struct drvmgr_dev *dev, void *arg),
518  void *arg,
519  int options);
520 
529 extern int drvmgr_get_dev(
530  struct drvmgr_drv *drv,
531  int minor,
532  struct drvmgr_dev **pdev);
533 
540 extern int drvmgr_freq_get(
541  struct drvmgr_dev *dev,
542  int options,
543  unsigned int *freq_hz);
544 
546 extern int drvmgr_on_rootbus(struct drvmgr_dev *dev);
547 
554 extern int drvmgr_get_dev_prefix(struct drvmgr_dev *dev, char *dev_prefix);
555 
569 extern int drvmgr_interrupt_register(
570  struct drvmgr_dev *dev,
571  int index,
572  const char *info,
573  drvmgr_isr isr,
574  void *arg);
575 
586 extern int drvmgr_interrupt_unregister(
587  struct drvmgr_dev *dev,
588  int index,
589  drvmgr_isr isr,
590  void *arg);
591 
601 extern int drvmgr_interrupt_clear(
602  struct drvmgr_dev *dev,
603  int index);
604 
615 extern int drvmgr_interrupt_unmask(
616  struct drvmgr_dev *dev,
617  int index);
618 
627 extern int drvmgr_interrupt_mask(
628  struct drvmgr_dev *dev,
629  int index);
630 
632 enum drvmgr_tr_opts {
633  /* Translate CPU RAM Address (input) to DMA unit accessible address
634  * (output), this is an upstreams translation in reverse order.
635  *
636  * Typical Usage:
637  * It is common to translate a CPU accessible RAM address to an
638  * address that DMA units can access over bridges.
639  */
640  CPUMEM_TO_DMA = 0x0,
641 
642  /* Translate DMA Unit Accessible address mapped to CPU RAM (input) to
643  * CPU accessible address (output). This is an upstreams translation.
644  *
645  * Typical Usage (not often used):
646  * The DMA unit descriptors contain pointers to DMA buffers located at
647  * CPU RAM addresses that the DMA unit can access, the CPU processes
648  * the descriptors and want to access the data but a translation back
649  * to CPU address is required.
650  */
651  CPUMEM_FROM_DMA = 0x1,
652 
653  /* Translate DMA Memory Address (input) to CPU accessible address
654  * (output), this is a downstreams translation in reverse order.
655  *
656  * Typical Usage:
657  * A PCI network card puts packets into its memory not doing DMA over
658  * PCI, in order for the CPU to access them the PCI address must be
659  * translated.
660  */
661  DMAMEM_TO_CPU = 0x2,
662 
663  /* Translate CPU accessible address (input) mapped to DMA Memory Address
664  * to DMA Unit accessible address (output). This is a downstreams
665  * translation.
666  */
667  DMAMEM_FROM_CPU = 0x3,
668 };
669 #define DRVMGR_TR_REVERSE 0x1 /* do reverse translation direction order */
670 #define DRVMGR_TR_PATH 0x2 /* 0x0=down-stream 0x2=up-stream address path */
671 
708 extern unsigned int drvmgr_translate(
709  struct drvmgr_dev *dev,
710  unsigned int options,
711  void *src_address,
712  void **dst_address);
713 
714 /* Translate addresses between buses, used internally to implement
715  * drvmgr_translate. Function is not limited to translate from/to root bus
716  * where CPU is resident, however buses must be on a straight path relative
717  * to each other (parent of parent of parent and so on).
718  *
719  * \param from src_address is given for this bus
720  * \param to src_address is translated to this bus
721  * \param reverse Selects translation method, if map entries are used in
722  * the reverse order (map_up->to is used as map_up->from)
723  * \param src_address Address to be translated
724  * \param dst_address Translated address is stored here on success (return=0)
725  *
726  * Returns 0 if unable to translate. The remaining length from the given
727  * address of the map is returned on success and the result is stored into
728  * *dst_address. For example if a map starts at 0x40000000 of size 0x100000
729  * the result will be 0x40000 if the address was translated into 0x400C0000.
730  * If dev is on root-bus no translation is performed 0xffffffff is returned.
731  * and src_address is stored in *dst_address.
732  */
733 extern unsigned int drvmgr_translate_bus(
734  struct drvmgr_bus *from,
735  struct drvmgr_bus *to,
736  int reverse,
737  void *src_address,
738  void **dst_address);
739 
740 /* Calls drvmgr_translate() to translate an address range and checks the result,
741  * a printout is generated if the check fails. All parameters are passed on to
742  * drvmgr_translate() except for size, see paramters of drvmgr_translate().
743  *
744  * If size=0 only the starting address is not checked.
745  *
746  * If mapping failes a non-zero result is returned.
747  */
748 extern int drvmgr_translate_check(
749  struct drvmgr_dev *dev,
750  unsigned int options,
751  void *src_address,
752  void **dst_address,
753  unsigned int size);
754 
759 extern int drvmgr_func_get(void *obj, int funcid, void **func);
760 
762 extern int drvmgr_func_call(void *obj, int funcid, void *a, void *b, void *c, void *d);
763 
764 /* Builds a Function ID.
765  *
766  * Used to request optional functions by a bus or device driver
767  */
768 #define DRVMGR_FUNCID(major, minor) ((((major) & 0xfff) << 20) | ((minor) & 0xfffff))
769 #define DRVMGR_FUNCID_NONE 0
770 #define DRVMGR_FUNCID_END DRVMGR_FUNCID(DRVMGR_FUNCID_NONE, 0)
771 
772 /* Major Function ID. Most significant 12-bits. */
773 enum {
774  FUNCID_NONE = 0x000,
775  FUNCID_RW = 0x001, /* Read/Write functions */
776 };
777 
778 /* Select Sub-Function Read/Write function by ID */
779 #define RW_SIZE_1 0x00001 /* Access Size */
780 #define RW_SIZE_2 0x00002
781 #define RW_SIZE_4 0x00004
782 #define RW_SIZE_8 0x00008
783 #define RW_SIZE_ANY 0x00000
784 #define RW_SIZE(id) ((unsigned int)(id) & 0xf)
785 
786 #define RW_DIR_ANY 0x00000 /* Access Direction */
787 #define RW_READ 0x00000 /* Read */
788 #define RW_WRITE 0x00010 /* Write */
789 #define RW_SET 0x00020 /* Write with same value (memset) */
790 #define RW_DIR(id) (((unsigned int)(id) >> 4) & 0x3)
791 
792 #define RW_RAW 0x00000 /* Raw access - no swapping (machine default) */
793 #define RW_LITTLE 0x00040 /* Little Endian */
794 #define RW_BIG 0x00080 /* Big Endian */
795 #define RW_ENDIAN(id) (((unsigned int)(id) >> 6) & 0x3)
796 
797 #define RW_TYPE_ANY 0x00000 /* Access type */
798 #define RW_REG 0x00100
799 #define RW_MEM 0x00200
800 #define RW_MEMREG 0x00300
801 #define RW_CFG 0x00400
802 #define RW_TYPE(id) (((unsigned int)(id) >> 8) & 0xf)
803 
804 #define RW_ARG 0x01000 /* Optional Argument */
805 #define RW_ERR 0x02000 /* Optional Error Handler */
806 
807 /* Build a Read/Write function ID */
808 #define DRVMGR_RWFUNC(minor) DRVMGR_FUNCID(FUNCID_RW, minor)
809 
810 /* Argument to Read/Write functions, the "void *arg" pointer is returned by
811  * RW_ARG. If NULL is returned no argument is needed.
812  */
813 struct drvmgr_rw_arg {
814  void *arg;
815  struct drvmgr_dev *dev;
816 };
817 
818 /* Standard Read/Write function types */
819 typedef uint8_t (*drvmgr_r8)(uint8_t *srcadr);
820 typedef uint16_t (*drvmgr_r16)(uint16_t *srcadr);
821 typedef uint32_t (*drvmgr_r32)(uint32_t *srcadr);
822 typedef uint64_t (*drvmgr_r64)(uint64_t *srcadr);
823 typedef void (*drvmgr_w8)(uint8_t *dstadr, uint8_t data);
824 typedef void (*drvmgr_w16)(uint16_t *dstadr, uint16_t data);
825 typedef void (*drvmgr_w32)(uint32_t *dstadr, uint32_t data);
826 typedef void (*drvmgr_w64)(uint64_t *dstadr, uint64_t data);
827 /* READ/COPY a memory area located on bus into CPU memory.
828  * From 'src' (remote) to the destination 'dest' (local), n=number of bytes
829  */
830 typedef int (*drvmgr_rmem)(void *dest, const void *src, int n);
831 /* WRITE/COPY a user buffer located in CPU memory to a location on the bus.
832  * From 'src' (local) to the destination 'dest' (remote), n=number of bytes
833  */
834 typedef int (*drvmgr_wmem)(void *dest, const void *src, int n);
835 /* Set a memory area to the byte value given in c, see LIBC memset(). Memset is
836  * implemented by calling wmem() multiple times with a "large" buffer.
837  */
838 typedef int (*drvmgr_memset)(void *dstadr, int c, size_t n);
839 
840 /* Read/Write function types with additional argument */
841 typedef uint8_t (*drvmgr_r8_arg)(uint8_t *srcadr, void *a);
842 typedef uint16_t (*drvmgr_r16_arg)(uint16_t *srcadr, void *a);
843 typedef uint32_t (*drvmgr_r32_arg)(uint32_t *srcadr, void *a);
844 typedef uint64_t (*drvmgr_r64_arg)(uint64_t *srcadr, void *a);
845 typedef void (*drvmgr_w8_arg)(uint8_t *dstadr, uint8_t data, void *a);
846 typedef void (*drvmgr_w16_arg)(uint16_t *dstadr, uint16_t data, void *a);
847 typedef void (*drvmgr_w32_arg)(uint32_t *dstadr, uint32_t data, void *a);
848 typedef void (*drvmgr_w64_arg)(uint64_t *dstadr, uint64_t data, void *a);
849 typedef int (*drvmgr_rmem_arg)(void *dest, const void *src, int n, void *a);
850 typedef int (*drvmgr_wmem_arg)(void *dest, const void *src, int n, void *a);
851 typedef int (*drvmgr_memset_arg)(void *dstadr, int c, size_t n, void *a);
852 
853 /* Report an error to the parent bus of the device */
854 typedef void (*drvmgr_rw_err)(struct drvmgr_rw_arg *a, struct drvmgr_bus *bus,
855  int funcid, void *adr);
856 
857 /* Helper function for buses that implement the memset() over wmem() */
858 extern void drvmgr_rw_memset(
859  void *dstadr,
860  int c,
861  size_t n,
862  void *a,
863  drvmgr_wmem_arg wmem
864  );
865 
866 /*** PRINT INFORMATION ABOUT DRIVER MANAGER ***/
867 
892 extern int drvmgr_for_each_listdev(
893  struct drvmgr_list *devlist,
894  unsigned int state_set_mask,
895  unsigned int state_clr_mask,
896  int (*func)(struct drvmgr_dev *dev, void *arg),
897  void *arg);
898 
899 /* Print all devices */
900 #define PRINT_DEVS_FAILED 0x01 /* Failed during initialization */
901 #define PRINT_DEVS_ASSIGNED 0x02 /* Driver assigned */
902 #define PRINT_DEVS_UNASSIGNED 0x04 /* Driver not assigned */
903 #define PRINT_DEVS_IGNORED 0x08 /* Device ignored on user's request */
904 #define PRINT_DEVS_ALL (PRINT_DEVS_FAILED | \
905  PRINT_DEVS_ASSIGNED | \
906  PRINT_DEVS_UNASSIGNED |\
907  PRINT_DEVS_IGNORED)
908 
910 extern void drvmgr_summary(void);
911 
913 extern void drvmgr_print_devs(unsigned int options);
914 
916 extern void drvmgr_print_topo(void);
917 
921 extern void drvmgr_print_mem(void);
922 
923 #define OPTION_DEV_GENINFO 0x00000001
924 #define OPTION_DEV_BUSINFO 0x00000002
925 #define OPTION_DEV_DRVINFO 0x00000004
926 #define OPTION_DRV_DEVS 0x00000100
927 #define OPTION_BUS_DEVS 0x00010000
928 #define OPTION_RECURSIVE 0x01000000
929 #define OPTION_INFO_ALL 0xffffffff
930 
932 extern void drvmgr_info(void *id, unsigned int options);
933 
935 extern void drvmgr_info_dev(struct drvmgr_dev *dev, unsigned int options);
936 
938 extern void drvmgr_info_bus(struct drvmgr_bus *bus, unsigned int options);
939 
941 extern void drvmgr_info_drv(struct drvmgr_drv *drv, unsigned int options);
942 
944 extern void drvmgr_info_devs_on_bus(struct drvmgr_bus *bus, unsigned int options);
945 
947 extern void drvmgr_info_devs(unsigned int options);
948 
950 extern void drvmgr_info_drvs(unsigned int options);
951 
953 extern void drvmgr_info_buses(unsigned int options);
954 
956 extern struct drvmgr_drv *drvmgr_drv_by_id(uint64_t id);
957 
959 extern struct drvmgr_drv *drvmgr_drv_by_name(const char *name);
960 
962 extern struct drvmgr_dev *drvmgr_dev_by_name(const char *name);
963 
964 #ifdef __cplusplus
965 }
966 #endif
967 
968 #endif
void drvmgr_info_buses(unsigned int options)
Get information about all buses in the system.
Definition: drvmgr_print.c:447
int drvmgr_children_unregister(struct drvmgr_bus *bus)
Unregister all child devices of a bus.
Definition: drvmgr_unregister.c:22
struct drvmgr_bus * parent
Bus that this device resides on.
Definition: drvmgr.h:278
void drvmgr_info(void *id, unsigned int options)
Print information about a driver manager object (device, driver, bus)
Definition: drvmgr_print.c:384
void drvmgr_info_drv(struct drvmgr_drv *drv, unsigned int options)
Get information about a driver.
Definition: drvmgr_print.c:347
int drvmgr_drv_register(struct drvmgr_drv *drv)
Register a driver.
Definition: drvmgr.c:348
int drvmgr_interrupt_unregister(struct drvmgr_dev *dev, int index, drvmgr_isr isr, void *arg)
Unregister an interrupt handler.
Definition: drvmgr_drvinf.c:97
void drvmgr_print_devs(unsigned int options)
Print devices with certain condictions met according to &#39;options&#39;.
Definition: drvmgr_print.c:41
int drvmgr_interrupt_mask(struct drvmgr_dev *dev, int index)
Force masking/disable an interrupt on the interrupt controller, this is not normally performed since ...
Definition: drvmgr_drvinf.c:132
int drvmgr_dev_register(struct drvmgr_dev *dev)
Register a device.
Definition: drvmgr.c:475
Definition: drvmgr.h:154
Bus information.
Definition: drvmgr.h:233
void drvmgr_info_dev(struct drvmgr_dev *dev, unsigned int options)
Get information about a device.
Definition: drvmgr_print.c:238
Bus operations.
Definition: drvmgr.h:129
struct drvmgr_drv * next
Next Driver.
Definition: drvmgr.h:303
void bsp_driver_level_hook(int level)
This function must be defined by the BSP when the driver manager is enabled and initialized during BS...
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
drvmgr_tr_opts
drvmgr_translate() translation options
Definition: drvmgr.h:633
int state
Init State of Bus, BUS_STATE_*.
Definition: drvmgr.h:250
int drvmgr_func_get(void *obj, int funcid, void **func)
Get function pointer from Device Driver or Bus Driver.
Definition: drvmgr_func.c:14
void drvmgr_bus_res_add(struct drvmgr_bus *bus, struct drvmgr_bus_res *bres)
Add resources to a bus, typically used by a bus driver.
Definition: drvmgr.c:635
int drvmgr_freq_get(struct drvmgr_dev *dev, int options, unsigned int *freq_hz)
Get Bus frequency in Hertz.
Definition: drvmgr_drvinf.c:53
struct drvmgr_key * drvmgr_key_get(struct drvmgr_key *keys, char *key_name)
Return the one key that matches key name from a driver keys array.
Definition: drvmgr_res.c:55
void * priv
Private data structure used by BUS driver.
Definition: drvmgr.h:239
Definition: drvmgr.h:194
struct drvmgr_drv * drvmgr_drv_by_name(const char *name)
Get Driver by Driver Name.
Definition: drvmgr_by_name.c:16
Bus resource list node.
Definition: drvmgr.h:210
MAP entry.
Definition: drvmgr.h:221
RTEMS_INLINE_ROUTINE struct drvmgr_drv * drvmgr_get_drv(struct drvmgr_dev *dev)
Get Driver of device.
Definition: drvmgr.h:495
void drvmgr_print_topo(void)
Print device/bus topology.
Definition: drvmgr_print.c:97
void drvmgr_info_devs_on_bus(struct drvmgr_bus *bus, unsigned int options)
Get information about all devices on a bus.
Definition: drvmgr_print.c:398
int drvmgr_interrupt_clear(struct drvmgr_dev *dev, int index)
Clear (ACK) pending interrupt.
Definition: drvmgr_drvinf.c:112
int drvmgr_init(void)
Init driver manager all in one go, will call _DRV_Manager_initialization(), then _DRV_Manager_init_le...
Definition: drvmgr_init.c:16
struct drvmgr_dev * next_in_bus
Next device on the same bus.
Definition: drvmgr.h:274
int drvmgr_keys_get(struct drvmgr_dev *dev, struct drvmgr_key **keys)
Find all the resource keys for a device among all driver resources on a bus.
Definition: drvmgr_res.c:15
Device information.
Definition: drvmgr.h:271
int drvmgr_func_call(void *obj, int funcid, void *a, void *b, void *c, void *d)
Lookup function and call it directly with the four optional arguments.
Definition: drvmgr_func_call.c:14
void drvmgr_info_drvs(unsigned int options)
Get information about all drivers in the system.
Definition: drvmgr_print.c:434
Union of different values.
Definition: drvmgr.h:187
struct drvmgr_dev * next
Next device.
Definition: drvmgr.h:273
struct drvmgr_dev * drvmgr_dev_by_name(const char *name)
Get Device by Device Name.
Definition: drvmgr_dev_by_name.c:27
void _DRV_Manager_init_level(int level)
Take all devices into init level &#39;level&#39;, all devices registered later will directly be taken into th...
Definition: drvmgr.c:68
Definition: drvmgr.h:814
union drvmgr_key_value * drvmgr_key_val_get(struct drvmgr_key *keys, char *key_name, enum drvmgr_kt key_type)
Extract key value from the key in the keys array matching name and type.
Definition: drvmgr_res.c:73
void drvmgr_info_devs(unsigned int options)
Get information about all devices in the system (on all buses)
Definition: drvmgr_print.c:423
struct drvmgr_dev * next_in_drv
Next device using the same driver.
Definition: drvmgr.h:275
int drvmgr_get_dev_prefix(struct drvmgr_dev *dev, char *dev_prefix)
Get device name prefix, this name can be used to register a unique name in the bus->error filesystem ...
Definition: drvmgr_drvinf.c:65
int drvmgr_bus_register(struct drvmgr_bus *bus)
Register a bus.
Definition: drvmgr.c:570
void _DRV_Manager_initialization(void)
Initialize data structures of the driver management system.
Definition: drvmgr.c:85
char * dev_prefix
Optional name prefix.
Definition: drvmgr.h:122
RTEMS_INLINE_ROUTINE struct drvmgr_bus * drvmgr_get_parent(struct drvmgr_dev *dev)
Get parent bus.
Definition: drvmgr.h:485
int drvmgr_dev_unregister(struct drvmgr_dev *dev)
Remove a device, and all its children devices if device is a bus device.
Definition: drvmgr_unregister.c:151
int drvmgr_alloc_dev(struct drvmgr_dev **pdev, int extra)
Allocate a device structure, if no memory available rtems_error_fatal_occurred is called...
Definition: drvmgr.c:597
int drvmgr_get_dev(struct drvmgr_drv *drv, int minor, struct drvmgr_dev **pdev)
Get Device pointer from Driver and Driver minor number.
Definition: drvmgr_drvinf.c:28
void drvmgr_print_mem(void)
Print the memory usage Only accounts for data structures.
Definition: drvmgr_print.c:106
union drvmgr_key_value * drvmgr_dev_key_get(struct drvmgr_dev *dev, char *key_name, enum drvmgr_kt key_type)
Get key value from the bus resources matching [device, key name, key type] if no matching key is foun...
Definition: drvmgr_res.c:90
int drvmgr_for_each_listdev(struct drvmgr_list *devlist, unsigned int state_set_mask, unsigned int state_clr_mask, int(*func)(struct drvmgr_dev *dev, void *arg), void *arg)
Calls func() for every device found matching the search requirements of set_mask and clr_mask...
Definition: drvmgr_for_each_list_dev.c:15
void drvmgr_summary(void)
Print number of devices, buses and drivers.
Definition: drvmgr_print.c:182
unsigned int drvmgr_translate(struct drvmgr_dev *dev, unsigned int options, void *src_address, void **dst_address)
Translate an address on one bus to an address on another bus.
Definition: drvmgr_translate.c:130
int drvmgr_alloc_bus(struct drvmgr_bus **pbus, int extra)
Allocate a bus structure, if no memory available rtems_error_fatal_occurred is called.
Definition: drvmgr.c:616
int drvmgr_interrupt_unmask(struct drvmgr_dev *dev, int index)
Force unmasking/enableing an interrupt on the interrupt controller, this is not normally used...
Definition: drvmgr_drvinf.c:122
Driver resource entry, Driver resources for a certain device instance, containing a number of keys wh...
Definition: drvmgr.h:203
Basic Definitions.
Driver operations, function pointers.
Definition: drvmgr.h:293
Device driver description.
Definition: drvmgr.h:301
void * priv
Pointer to driver private device structure.
Definition: drvmgr.h:282
int level
Initialization Level of Bus.
Definition: drvmgr.h:249
int drvmgr_on_rootbus(struct drvmgr_dev *dev)
Return 0 if dev is not located on the root bus, 1 if on root bus.
Definition: drvmgr_drvinf.c:142
void(* drvmgr_drv_reg_func)(void)
Structure defines a function pointer called when driver manager is ready for drivers to register them...
Definition: drvmgr.h:319
struct drvmgr_drv * drvmgr_drv_by_id(uint64_t id)
Get Driver by Driver ID.
Definition: drvmgr_by_id.c:15
struct drvmgr_drv * drv
The driver owning this device.
Definition: drvmgr.h:277
char * name
Name of Device Hardware.
Definition: drvmgr.h:281
struct drvmgr_bus * next
Next Bus.
Definition: drvmgr.h:237
Bus parameters used by driver interface functions to aquire information about bus.
Definition: drvmgr.h:121
void drvmgr_info_bus(struct drvmgr_bus *bus, unsigned int options)
Get information about a bus.
Definition: drvmgr_print.c:301
int drvmgr_bus_unregister(struct drvmgr_bus *bus)
Unregister a bus.
Definition: drvmgr_unregister.c:44
int drvmgr_interrupt_register(struct drvmgr_dev *dev, int index, const char *info, drvmgr_isr isr, void *arg)
Register a shared interrupt handler.
Definition: drvmgr_drvinf.c:80
struct drvmgr_bus_res * next
Next resource node in list.
Definition: drvmgr.h:211
List description, Singly link list with head and tail pointers.
Definition: drvmgr_list.h:25
int error
Return code from bus->ops->initN()
Definition: drvmgr.h:251
int drvmgr_root_drv_register(struct drvmgr_drv *drv)
Register Root Bus device driver.
Definition: drvmgr.c:319