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