10ca3913dSOlivier Deprez /* 2*c56a85d0SHarrison Mutai * Copyright (c) 2019-2025, Arm Limited. All rights reserved. 30ca3913dSOlivier Deprez * 40ca3913dSOlivier Deprez * SPDX-License-Identifier: BSD-3-Clause 50ca3913dSOlivier Deprez */ 60ca3913dSOlivier Deprez 70ca3913dSOlivier Deprez #ifndef DEV_H 80ca3913dSOlivier Deprez #define DEV_H 90ca3913dSOlivier Deprez 100ca3913dSOlivier Deprez #include <cdefs.h> 110ca3913dSOlivier Deprez #include <lib/debugfs.h> 120ca3913dSOlivier Deprez #include <stddef.h> 130ca3913dSOlivier Deprez 140ca3913dSOlivier Deprez /* FIXME: need configurability */ 150ca3913dSOlivier Deprez #define NR_CHANS 10 160ca3913dSOlivier Deprez #define NR_CONSS 1 170ca3913dSOlivier Deprez #define NR_BINDS 4 180ca3913dSOlivier Deprez #define NR_FILES 18 190ca3913dSOlivier Deprez 200ca3913dSOlivier Deprez #define NODEV 255 210ca3913dSOlivier Deprez #define CHDIR (1 << 15) 220ca3913dSOlivier Deprez 230ca3913dSOlivier Deprez #define SYNCDEV 0 240ca3913dSOlivier Deprez #define SYNCALL 1 250ca3913dSOlivier Deprez 260ca3913dSOlivier Deprez typedef struct dev dev_t; 270ca3913dSOlivier Deprez typedef struct chan chan_t; 280ca3913dSOlivier Deprez typedef struct dirtab dirtab_t; 290ca3913dSOlivier Deprez typedef int devgen_t(chan_t *, const dirtab_t *, int, int, dir_t *); 300ca3913dSOlivier Deprez typedef struct attr attr_t; 310ca3913dSOlivier Deprez 320ca3913dSOlivier Deprez enum { 330ca3913dSOlivier Deprez DEV_ROOT_QROOT, 340ca3913dSOlivier Deprez DEV_ROOT_QDEV, 350ca3913dSOlivier Deprez DEV_ROOT_QFIP, 360ca3913dSOlivier Deprez DEV_ROOT_QBLOBS, 370ca3913dSOlivier Deprez DEV_ROOT_QBLOBCTL, 380ca3913dSOlivier Deprez DEV_ROOT_QPSCI 390ca3913dSOlivier Deprez }; 400ca3913dSOlivier Deprez 410ca3913dSOlivier Deprez /******************************************************************************* 420ca3913dSOlivier Deprez * This structure contains the necessary information to represent a directory 430ca3913dSOlivier Deprez * of the filesystem. 440ca3913dSOlivier Deprez ******************************************************************************/ 450ca3913dSOlivier Deprez struct dirtab { 460ca3913dSOlivier Deprez char name[NAMELEN]; 470ca3913dSOlivier Deprez qid_t qid; 480ca3913dSOlivier Deprez long length; 490ca3913dSOlivier Deprez unsigned char perm; 500ca3913dSOlivier Deprez void *data; 510ca3913dSOlivier Deprez }; 520ca3913dSOlivier Deprez 530ca3913dSOlivier Deprez /******************************************************************************* 540ca3913dSOlivier Deprez * This structure defines the interface of device drivers. 550ca3913dSOlivier Deprez * Each driver must implement a subset of those functions. 560ca3913dSOlivier Deprez * It is possible to redirect to default implementations defined in dev.c. 570ca3913dSOlivier Deprez ******************************************************************************/ 580ca3913dSOlivier Deprez /* FIXME: comments for the callbacks */ 590ca3913dSOlivier Deprez struct dev { 600ca3913dSOlivier Deprez char id; 610ca3913dSOlivier Deprez int (*stat)(chan_t *c, const char *file, dir_t *dir); 620ca3913dSOlivier Deprez int (*walk)(chan_t *c, const char *name); 630ca3913dSOlivier Deprez int (*read)(chan_t *c, void *buf, int n); 640ca3913dSOlivier Deprez int (*write)(chan_t *c, void *buf, int n); 650ca3913dSOlivier Deprez int (*seek)(chan_t *c, long off, int whence); 660ca3913dSOlivier Deprez chan_t *(*clone)(chan_t *c, chan_t *nc); 670ca3913dSOlivier Deprez chan_t *(*attach)(int id, int dev); 680ca3913dSOlivier Deprez chan_t *(*mount)(chan_t *c, const char *spec); 690ca3913dSOlivier Deprez }; 700ca3913dSOlivier Deprez 710ca3913dSOlivier Deprez /******************************************************************************* 720ca3913dSOlivier Deprez * This structure defines the channel structure. 730ca3913dSOlivier Deprez * A channel is a handle on an element of the filesystem. 740ca3913dSOlivier Deprez ******************************************************************************/ 750ca3913dSOlivier Deprez struct chan { 76*c56a85d0SHarrison Mutai unsigned long offset; 770ca3913dSOlivier Deprez qid_t qid; 780ca3913dSOlivier Deprez unsigned char index; /* device index in devtab */ 790ca3913dSOlivier Deprez unsigned char dev; 800ca3913dSOlivier Deprez unsigned char mode; 810ca3913dSOlivier Deprez }; 820ca3913dSOlivier Deprez 830ca3913dSOlivier Deprez /******************************************************************************* 840ca3913dSOlivier Deprez * This structure defines an abstract argument passed to physical drivers from 850ca3913dSOlivier Deprez * the configuration file. 860ca3913dSOlivier Deprez ******************************************************************************/ 870ca3913dSOlivier Deprez struct attr { 880ca3913dSOlivier Deprez char *key; 890ca3913dSOlivier Deprez char *value; 900ca3913dSOlivier Deprez }; 910ca3913dSOlivier Deprez 920ca3913dSOlivier Deprez chan_t *path_to_channel(const char *path, int mode); 930ca3913dSOlivier Deprez chan_t *clone(chan_t *c, chan_t *nc); 940ca3913dSOlivier Deprez chan_t *attach(int id, int dev); 950ca3913dSOlivier Deprez void channel_close(chan_t *c); 96*c56a85d0SHarrison Mutai int buf_to_channel(chan_t *c, void *dst, void *src, size_t nbytes, long len); 970ca3913dSOlivier Deprez int dirread(chan_t *c, dir_t *dir, const dirtab_t *tab, 980ca3913dSOlivier Deprez int ntab, devgen_t *gen); 990ca3913dSOlivier Deprez void make_dir_entry(chan_t *c, dir_t *dir, const char *name, long length, 1000ca3913dSOlivier Deprez qid_t qid, unsigned int mode); 1010ca3913dSOlivier Deprez void devlink(void); 1020ca3913dSOlivier Deprez 1030ca3913dSOlivier Deprez chan_t *devattach(int id, int dev); 1040ca3913dSOlivier Deprez int devseek(chan_t *c, long off, int whence); 1050ca3913dSOlivier Deprez chan_t *devclone(chan_t *c, chan_t *nc); 1060ca3913dSOlivier Deprez int devgen(chan_t *c, const dirtab_t *tab, int ntab, int n, dir_t *dir); 1070ca3913dSOlivier Deprez int devwalk(chan_t *c, const char *name, const dirtab_t *tab, int ntab, 1080ca3913dSOlivier Deprez devgen_t *gen); 1090ca3913dSOlivier Deprez int devstat(chan_t *dirc, const char *file, dir_t *dir, 1100ca3913dSOlivier Deprez const dirtab_t *tab, int ntab, devgen_t *gen); 1110ca3913dSOlivier Deprez 1120ca3913dSOlivier Deprez chan_t *deverrmount(chan_t *c, const char *spec); 1130ca3913dSOlivier Deprez int deverrwrite(chan_t *c, void *buf, int n); 1140ca3913dSOlivier Deprez int deverrseek(chan_t *c, long off, int whence); 1150ca3913dSOlivier Deprez 1160ca3913dSOlivier Deprez extern dev_t *const devtab[]; 1170ca3913dSOlivier Deprez 1180ca3913dSOlivier Deprez void __dead2 devpanic(const char *cause); 1190ca3913dSOlivier Deprez 1200ca3913dSOlivier Deprez #endif /* DEV_H */ 121