Commit 0ca3913d authored by Olivier Deprez's avatar Olivier Deprez
Browse files

debugfs: add 9p device interface



The 9p interface provides abstraction layers allowing the software
that uses devices to be independent from the hardware.

This patch provides a file system abstraction to link drivers to their
devices and propose a common interface to expose driver operations to
higher layers. This file system can be used to access and configure a
device by doing read/write operations.
Signed-off-by: default avatarAmbroise Vincent <ambroise.vincent@arm.com>
Signed-off-by: default avatarOlivier Deprez <olivier.deprez@arm.com>
Change-Id: Ia9662393baf489855dc0c8f389fe4a0afbc9c255
parent fcccd358
...@@ -150,6 +150,15 @@ else ...@@ -150,6 +150,15 @@ else
endif endif
endif endif
# USE_DEBUGFS experimental feature recommended only in debug builds
ifeq (${USE_DEBUGFS},1)
ifeq (${DEBUG},1)
$(warning DEBUGFS experimental feature is enabled.)
else
$(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
endif
endif
################################################################################ ################################################################################
# Toolchain # Toolchain
################################################################################ ################################################################################
...@@ -734,6 +743,7 @@ $(eval $(call assert_boolean,SPIN_ON_BL1_EXIT)) ...@@ -734,6 +743,7 @@ $(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
$(eval $(call assert_boolean,SPM_MM)) $(eval $(call assert_boolean,SPM_MM))
$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT)) $(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
$(eval $(call assert_boolean,USE_COHERENT_MEM)) $(eval $(call assert_boolean,USE_COHERENT_MEM))
$(eval $(call assert_boolean,USE_DEBUGFS))
$(eval $(call assert_boolean,USE_ROMLIB)) $(eval $(call assert_boolean,USE_ROMLIB))
$(eval $(call assert_boolean,USE_TBBR_DEFS)) $(eval $(call assert_boolean,USE_TBBR_DEFS))
$(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY)) $(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY))
...@@ -800,6 +810,7 @@ $(eval $(call add_define,SPIN_ON_BL1_EXIT)) ...@@ -800,6 +810,7 @@ $(eval $(call add_define,SPIN_ON_BL1_EXIT))
$(eval $(call add_define,SPM_MM)) $(eval $(call add_define,SPM_MM))
$(eval $(call add_define,TRUSTED_BOARD_BOOT)) $(eval $(call add_define,TRUSTED_BOARD_BOOT))
$(eval $(call add_define,USE_COHERENT_MEM)) $(eval $(call add_define,USE_COHERENT_MEM))
$(eval $(call add_define,USE_DEBUGFS))
$(eval $(call add_define,USE_ROMLIB)) $(eval $(call add_define,USE_ROMLIB))
$(eval $(call add_define,USE_TBBR_DEFS)) $(eval $(call add_define,USE_TBBR_DEFS))
$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY)) $(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
......
...@@ -43,6 +43,11 @@ ifeq (${ENABLE_PMF}, 1) ...@@ -43,6 +43,11 @@ ifeq (${ENABLE_PMF}, 1)
BL31_SOURCES += lib/pmf/pmf_main.c BL31_SOURCES += lib/pmf/pmf_main.c
endif endif
include lib/debugfs/debugfs.mk
ifeq (${USE_DEBUGFS},1)
BL31_SOURCES += $(DEBUGFS_SRCS)
endif
ifeq (${EL3_EXCEPTION_HANDLING},1) ifeq (${EL3_EXCEPTION_HANDLING},1)
BL31_SOURCES += bl31/ehf.c BL31_SOURCES += bl31/ehf.c
endif endif
......
/*
* Copyright (c) 2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef DEBUGFS_H
#define DEBUGFS_H
#define NAMELEN 13 /* Maximum length of a file name */
#define PATHLEN 41 /* Maximum length of a path */
#define STATLEN 41 /* Size of static part of dir format */
#define ROOTLEN (2 + 4) /* Size needed to encode root string */
#define FILNAMLEN (2 + NAMELEN) /* Size needed to encode filename */
#define DIRLEN (STATLEN + FILNAMLEN + 3*ROOTLEN) /* Size of dir entry */
#define KSEEK_SET 0
#define KSEEK_CUR 1
#define KSEEK_END 2
#define NELEM(tab) (sizeof(tab) / sizeof((tab)[0]))
typedef unsigned short qid_t; /* FIXME: short type not recommended? */
/*******************************************************************************
* This structure contains the necessary information to represent a 9p
* directory.
******************************************************************************/
typedef struct {
char name[NAMELEN];
long length;
unsigned char mode;
unsigned char index;
unsigned char dev;
qid_t qid;
} dir_t;
/* Permission definitions used as flags */
#define O_READ (1 << 0)
#define O_WRITE (1 << 1)
#define O_RDWR (1 << 2)
#define O_BIND (1 << 3)
#define O_DIR (1 << 4)
#define O_STAT (1 << 5)
/* 9p interface */
int mount(const char *srv, const char *mnt, const char *spec);
int create(const char *name, int flags);
int open(const char *name, int flags);
int close(int fd);
int read(int fd, void *buf, int n);
int write(int fd, void *buf, int n);
int seek(int fd, long off, int whence);
int bind(const char *path, const char *where);
int stat(const char *path, dir_t *dir);
/* DebugFS initialization */
void debugfs_init(void);
#endif /* DEBUGFS_H */
/*
* Copyright (c) 2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "dev.h"
static const dirtab_t blobtab[] = {
{"ctl", DEV_ROOT_QBLOBCTL, 0, O_READ}
};
#
# Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
DEBUGFS_SRCS := $(addprefix lib/debugfs/, \
dev.c \
devc.c \
devroot.c)
This diff is collapsed.
/*
* Copyright (c) 2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef DEV_H
#define DEV_H
#include <cdefs.h>
#include <lib/debugfs.h>
#include <stddef.h>
/* FIXME: need configurability */
#define NR_CHANS 10
#define NR_CONSS 1
#define NR_BINDS 4
#define NR_FILES 18
#define NODEV 255
#define CHDIR (1 << 15)
#define SYNCDEV 0
#define SYNCALL 1
typedef struct dev dev_t;
typedef struct chan chan_t;
typedef struct dirtab dirtab_t;
typedef int devgen_t(chan_t *, const dirtab_t *, int, int, dir_t *);
typedef struct attr attr_t;
enum {
DEV_ROOT_QROOT,
DEV_ROOT_QDEV,
DEV_ROOT_QFIP,
DEV_ROOT_QBLOBS,
DEV_ROOT_QBLOBCTL,
DEV_ROOT_QPSCI
};
/*******************************************************************************
* This structure contains the necessary information to represent a directory
* of the filesystem.
******************************************************************************/
struct dirtab {
char name[NAMELEN];
qid_t qid;
long length;
unsigned char perm;
void *data;
};
/*******************************************************************************
* This structure defines the interface of device drivers.
* Each driver must implement a subset of those functions.
* It is possible to redirect to default implementations defined in dev.c.
******************************************************************************/
/* FIXME: comments for the callbacks */
struct dev {
char id;
int (*stat)(chan_t *c, const char *file, dir_t *dir);
int (*walk)(chan_t *c, const char *name);
int (*read)(chan_t *c, void *buf, int n);
int (*write)(chan_t *c, void *buf, int n);
int (*seek)(chan_t *c, long off, int whence);
chan_t *(*clone)(chan_t *c, chan_t *nc);
chan_t *(*attach)(int id, int dev);
chan_t *(*mount)(chan_t *c, const char *spec);
};
/*******************************************************************************
* This structure defines the channel structure.
* A channel is a handle on an element of the filesystem.
******************************************************************************/
struct chan {
long offset;
qid_t qid;
unsigned char index; /* device index in devtab */
unsigned char dev;
unsigned char mode;
};
/*******************************************************************************
* This structure defines an abstract argument passed to physical drivers from
* the configuration file.
******************************************************************************/
struct attr {
char *key;
char *value;
};
chan_t *path_to_channel(const char *path, int mode);
chan_t *clone(chan_t *c, chan_t *nc);
chan_t *attach(int id, int dev);
void channel_close(chan_t *c);
int buf_to_channel(chan_t *c, void *dst, void *src, int nbytes, long len);
int dirread(chan_t *c, dir_t *dir, const dirtab_t *tab,
int ntab, devgen_t *gen);
void make_dir_entry(chan_t *c, dir_t *dir, const char *name, long length,
qid_t qid, unsigned int mode);
void devlink(void);
chan_t *devattach(int id, int dev);
int devseek(chan_t *c, long off, int whence);
chan_t *devclone(chan_t *c, chan_t *nc);
int devgen(chan_t *c, const dirtab_t *tab, int ntab, int n, dir_t *dir);
int devwalk(chan_t *c, const char *name, const dirtab_t *tab, int ntab,
devgen_t *gen);
int devstat(chan_t *dirc, const char *file, dir_t *dir,
const dirtab_t *tab, int ntab, devgen_t *gen);
chan_t *deverrmount(chan_t *c, const char *spec);
int deverrwrite(chan_t *c, void *buf, int n);
int deverrseek(chan_t *c, long off, int whence);
extern dev_t *const devtab[];
void __dead2 devpanic(const char *cause);
#endif /* DEV_H */
/*
* Copyright (c) 2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
typedef struct dev dev_t;
extern dev_t rootdevtab;
dev_t *const devtab[] = {
&rootdevtab,
0
};
void devlink(void)
{
}
/*
* Copyright (c) 2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <common/debug.h>
#include <lib/debugfs.h>
#include "blobs.h"
#include "dev.h"
/*******************************************************************************
* This array contains the directories available from the root directory.
******************************************************************************/
static const dirtab_t dirtab[] = {
{"dev", CHDIR | DEV_ROOT_QDEV, 0, O_READ},
{"blobs", CHDIR | DEV_ROOT_QBLOBS, 0, O_READ},
{"fip", CHDIR | DEV_ROOT_QFIP, 0, O_READ}
};
static const dirtab_t devfstab[] = {
};
/*******************************************************************************
* This function exposes the elements of the root directory.
* It also exposes the content of the dev and blobs directories.
******************************************************************************/
static int rootgen(chan_t *channel, const dirtab_t *tab, int ntab,
int n, dir_t *dir)
{
switch (channel->qid & ~CHDIR) {
case DEV_ROOT_QROOT:
tab = dirtab;
ntab = NELEM(dirtab);
break;
case DEV_ROOT_QDEV:
tab = devfstab;
ntab = NELEM(devfstab);
break;
case DEV_ROOT_QBLOBS:
tab = blobtab;
ntab = NELEM(blobtab);
break;
default:
return 0;
}
return devgen(channel, tab, ntab, n, dir);
}
static int rootwalk(chan_t *channel, const char *name)
{
return devwalk(channel, name, NULL, 0, rootgen);
}
/*******************************************************************************
* This function copies at most n bytes from the element referred by c into buf.
******************************************************************************/
static int rootread(chan_t *channel, void *buf, int size)
{
const dirtab_t *dp;
dir_t *dir;
if ((channel->qid & CHDIR) != 0) {
if (size < sizeof(dir_t)) {
return -1;
}
dir = buf;
return dirread(channel, dir, NULL, 0, rootgen);
}
/* Only makes sense when using debug language */
assert(channel->qid != DEV_ROOT_QBLOBCTL);
dp = &blobtab[channel->qid - DEV_ROOT_QBLOBCTL];
return buf_to_channel(channel, buf, dp->data, size, dp->length);
}
static int rootstat(chan_t *channel, const char *file, dir_t *dir)
{
return devstat(channel, file, dir, NULL, 0, rootgen);
}
const dev_t rootdevtab = {
.id = '/',
.stat = rootstat,
.clone = devclone,
.attach = devattach,
.walk = rootwalk,
.read = rootread,
.write = deverrwrite,
.mount = deverrmount,
.seek = devseek
};
...@@ -194,6 +194,9 @@ TRUSTED_BOARD_BOOT := 0 ...@@ -194,6 +194,9 @@ TRUSTED_BOARD_BOOT := 0
# Build option to choose whether Trusted Firmware uses Coherent memory or not. # Build option to choose whether Trusted Firmware uses Coherent memory or not.
USE_COHERENT_MEM := 1 USE_COHERENT_MEM := 1
# Build option to add debugfs support
USE_DEBUGFS := 0
# Build option to choose whether Trusted Firmware uses library at ROM # Build option to choose whether Trusted Firmware uses library at ROM
USE_ROMLIB := 0 USE_ROMLIB := 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment