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