xref: /rk3399_ARM-atf/lib/debugfs/dev.h (revision 0ca3913dd898ec0822d4984f8fd6eb86131f1088)
1*0ca3913dSOlivier Deprez /*
2*0ca3913dSOlivier Deprez  * Copyright (c) 2019, Arm Limited. All rights reserved.
3*0ca3913dSOlivier Deprez  *
4*0ca3913dSOlivier Deprez  * SPDX-License-Identifier: BSD-3-Clause
5*0ca3913dSOlivier Deprez  */
6*0ca3913dSOlivier Deprez 
7*0ca3913dSOlivier Deprez #ifndef DEV_H
8*0ca3913dSOlivier Deprez #define DEV_H
9*0ca3913dSOlivier Deprez 
10*0ca3913dSOlivier Deprez #include <cdefs.h>
11*0ca3913dSOlivier Deprez #include <lib/debugfs.h>
12*0ca3913dSOlivier Deprez #include <stddef.h>
13*0ca3913dSOlivier Deprez 
14*0ca3913dSOlivier Deprez /* FIXME: need configurability */
15*0ca3913dSOlivier Deprez #define NR_CHANS  10
16*0ca3913dSOlivier Deprez #define NR_CONSS  1
17*0ca3913dSOlivier Deprez #define NR_BINDS  4
18*0ca3913dSOlivier Deprez #define NR_FILES  18
19*0ca3913dSOlivier Deprez 
20*0ca3913dSOlivier Deprez #define NODEV     255
21*0ca3913dSOlivier Deprez #define CHDIR     (1 << 15)
22*0ca3913dSOlivier Deprez 
23*0ca3913dSOlivier Deprez #define SYNCDEV   0
24*0ca3913dSOlivier Deprez #define SYNCALL   1
25*0ca3913dSOlivier Deprez 
26*0ca3913dSOlivier Deprez typedef struct dev dev_t;
27*0ca3913dSOlivier Deprez typedef struct chan chan_t;
28*0ca3913dSOlivier Deprez typedef struct dirtab dirtab_t;
29*0ca3913dSOlivier Deprez typedef int devgen_t(chan_t *, const dirtab_t *, int, int, dir_t *);
30*0ca3913dSOlivier Deprez typedef struct attr attr_t;
31*0ca3913dSOlivier Deprez 
32*0ca3913dSOlivier Deprez enum {
33*0ca3913dSOlivier Deprez 	DEV_ROOT_QROOT,
34*0ca3913dSOlivier Deprez 	DEV_ROOT_QDEV,
35*0ca3913dSOlivier Deprez 	DEV_ROOT_QFIP,
36*0ca3913dSOlivier Deprez 	DEV_ROOT_QBLOBS,
37*0ca3913dSOlivier Deprez 	DEV_ROOT_QBLOBCTL,
38*0ca3913dSOlivier Deprez 	DEV_ROOT_QPSCI
39*0ca3913dSOlivier Deprez };
40*0ca3913dSOlivier Deprez 
41*0ca3913dSOlivier Deprez /*******************************************************************************
42*0ca3913dSOlivier Deprez  * This structure contains the necessary information to represent a directory
43*0ca3913dSOlivier Deprez  * of the filesystem.
44*0ca3913dSOlivier Deprez  ******************************************************************************/
45*0ca3913dSOlivier Deprez struct dirtab {
46*0ca3913dSOlivier Deprez 	char		name[NAMELEN];
47*0ca3913dSOlivier Deprez 	qid_t		qid;
48*0ca3913dSOlivier Deprez 	long		length;
49*0ca3913dSOlivier Deprez 	unsigned char	perm;
50*0ca3913dSOlivier Deprez 	void		*data;
51*0ca3913dSOlivier Deprez };
52*0ca3913dSOlivier Deprez 
53*0ca3913dSOlivier Deprez /*******************************************************************************
54*0ca3913dSOlivier Deprez  * This structure defines the interface of device drivers.
55*0ca3913dSOlivier Deprez  * Each driver must implement a subset of those functions.
56*0ca3913dSOlivier Deprez  * It is possible to redirect to default implementations defined in dev.c.
57*0ca3913dSOlivier Deprez  ******************************************************************************/
58*0ca3913dSOlivier Deprez /* FIXME: comments for the callbacks */
59*0ca3913dSOlivier Deprez struct dev {
60*0ca3913dSOlivier Deprez 	char id;
61*0ca3913dSOlivier Deprez 	int (*stat)(chan_t *c, const char *file, dir_t *dir);
62*0ca3913dSOlivier Deprez 	int (*walk)(chan_t *c, const char *name);
63*0ca3913dSOlivier Deprez 	int (*read)(chan_t *c, void *buf, int n);
64*0ca3913dSOlivier Deprez 	int (*write)(chan_t *c, void *buf, int n);
65*0ca3913dSOlivier Deprez 	int (*seek)(chan_t *c, long off, int whence);
66*0ca3913dSOlivier Deprez 	chan_t *(*clone)(chan_t *c, chan_t *nc);
67*0ca3913dSOlivier Deprez 	chan_t *(*attach)(int id, int dev);
68*0ca3913dSOlivier Deprez 	chan_t *(*mount)(chan_t *c, const char *spec);
69*0ca3913dSOlivier Deprez };
70*0ca3913dSOlivier Deprez 
71*0ca3913dSOlivier Deprez /*******************************************************************************
72*0ca3913dSOlivier Deprez  * This structure defines the channel structure.
73*0ca3913dSOlivier Deprez  * A channel is a handle on an element of the filesystem.
74*0ca3913dSOlivier Deprez  ******************************************************************************/
75*0ca3913dSOlivier Deprez struct chan {
76*0ca3913dSOlivier Deprez 	long		offset;
77*0ca3913dSOlivier Deprez 	qid_t		qid;
78*0ca3913dSOlivier Deprez 	unsigned char	index;	/* device index in devtab */
79*0ca3913dSOlivier Deprez 	unsigned char	dev;
80*0ca3913dSOlivier Deprez 	unsigned char	mode;
81*0ca3913dSOlivier Deprez };
82*0ca3913dSOlivier Deprez 
83*0ca3913dSOlivier Deprez /*******************************************************************************
84*0ca3913dSOlivier Deprez  * This structure defines an abstract argument passed to physical drivers from
85*0ca3913dSOlivier Deprez  * the configuration file.
86*0ca3913dSOlivier Deprez  ******************************************************************************/
87*0ca3913dSOlivier Deprez struct attr {
88*0ca3913dSOlivier Deprez 	char	*key;
89*0ca3913dSOlivier Deprez 	char	*value;
90*0ca3913dSOlivier Deprez };
91*0ca3913dSOlivier Deprez 
92*0ca3913dSOlivier Deprez chan_t *path_to_channel(const char *path, int mode);
93*0ca3913dSOlivier Deprez chan_t *clone(chan_t *c, chan_t *nc);
94*0ca3913dSOlivier Deprez chan_t *attach(int id, int dev);
95*0ca3913dSOlivier Deprez void channel_close(chan_t *c);
96*0ca3913dSOlivier Deprez int buf_to_channel(chan_t *c, void *dst, void *src, int nbytes, long len);
97*0ca3913dSOlivier Deprez int dirread(chan_t *c, dir_t *dir, const dirtab_t *tab,
98*0ca3913dSOlivier Deprez 	    int ntab, devgen_t *gen);
99*0ca3913dSOlivier Deprez void make_dir_entry(chan_t *c, dir_t *dir, const char *name, long length,
100*0ca3913dSOlivier Deprez 		    qid_t qid, unsigned int mode);
101*0ca3913dSOlivier Deprez void devlink(void);
102*0ca3913dSOlivier Deprez 
103*0ca3913dSOlivier Deprez chan_t *devattach(int id, int dev);
104*0ca3913dSOlivier Deprez int devseek(chan_t *c, long off, int whence);
105*0ca3913dSOlivier Deprez chan_t *devclone(chan_t *c, chan_t *nc);
106*0ca3913dSOlivier Deprez int devgen(chan_t *c, const dirtab_t *tab, int ntab, int n, dir_t *dir);
107*0ca3913dSOlivier Deprez int devwalk(chan_t *c, const char *name, const dirtab_t *tab, int ntab,
108*0ca3913dSOlivier Deprez 		   devgen_t *gen);
109*0ca3913dSOlivier Deprez int devstat(chan_t *dirc, const char *file, dir_t *dir,
110*0ca3913dSOlivier Deprez 		   const dirtab_t *tab, int ntab, devgen_t *gen);
111*0ca3913dSOlivier Deprez 
112*0ca3913dSOlivier Deprez chan_t *deverrmount(chan_t *c, const char *spec);
113*0ca3913dSOlivier Deprez int deverrwrite(chan_t *c, void *buf, int n);
114*0ca3913dSOlivier Deprez int deverrseek(chan_t *c, long off, int whence);
115*0ca3913dSOlivier Deprez 
116*0ca3913dSOlivier Deprez extern dev_t *const devtab[];
117*0ca3913dSOlivier Deprez 
118*0ca3913dSOlivier Deprez void __dead2 devpanic(const char *cause);
119*0ca3913dSOlivier Deprez 
120*0ca3913dSOlivier Deprez #endif /* DEV_H */
121