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 #include <assert.h> 8*91f16700Schasinglulu #include <common/debug.h> 9*91f16700Schasinglulu #include <lib/debugfs.h> 10*91f16700Schasinglulu 11*91f16700Schasinglulu #include "blobs.h" 12*91f16700Schasinglulu #include "dev.h" 13*91f16700Schasinglulu 14*91f16700Schasinglulu /******************************************************************************* 15*91f16700Schasinglulu * This array contains the directories available from the root directory. 16*91f16700Schasinglulu ******************************************************************************/ 17*91f16700Schasinglulu static const dirtab_t dirtab[] = { 18*91f16700Schasinglulu {"dev", CHDIR | DEV_ROOT_QDEV, 0, O_READ}, 19*91f16700Schasinglulu {"blobs", CHDIR | DEV_ROOT_QBLOBS, 0, O_READ}, 20*91f16700Schasinglulu {"fip", CHDIR | DEV_ROOT_QFIP, 0, O_READ} 21*91f16700Schasinglulu }; 22*91f16700Schasinglulu 23*91f16700Schasinglulu static const dirtab_t devfstab[] = { 24*91f16700Schasinglulu }; 25*91f16700Schasinglulu 26*91f16700Schasinglulu /******************************************************************************* 27*91f16700Schasinglulu * This function exposes the elements of the root directory. 28*91f16700Schasinglulu * It also exposes the content of the dev and blobs directories. 29*91f16700Schasinglulu ******************************************************************************/ 30*91f16700Schasinglulu static int rootgen(chan_t *channel, const dirtab_t *tab, int ntab, 31*91f16700Schasinglulu int n, dir_t *dir) 32*91f16700Schasinglulu { 33*91f16700Schasinglulu switch (channel->qid & ~CHDIR) { 34*91f16700Schasinglulu case DEV_ROOT_QROOT: 35*91f16700Schasinglulu tab = dirtab; 36*91f16700Schasinglulu ntab = NELEM(dirtab); 37*91f16700Schasinglulu break; 38*91f16700Schasinglulu case DEV_ROOT_QDEV: 39*91f16700Schasinglulu tab = devfstab; 40*91f16700Schasinglulu ntab = NELEM(devfstab); 41*91f16700Schasinglulu break; 42*91f16700Schasinglulu case DEV_ROOT_QBLOBS: 43*91f16700Schasinglulu tab = blobtab; 44*91f16700Schasinglulu ntab = NELEM(blobtab); 45*91f16700Schasinglulu break; 46*91f16700Schasinglulu default: 47*91f16700Schasinglulu return 0; 48*91f16700Schasinglulu } 49*91f16700Schasinglulu 50*91f16700Schasinglulu return devgen(channel, tab, ntab, n, dir); 51*91f16700Schasinglulu } 52*91f16700Schasinglulu 53*91f16700Schasinglulu static int rootwalk(chan_t *channel, const char *name) 54*91f16700Schasinglulu { 55*91f16700Schasinglulu return devwalk(channel, name, NULL, 0, rootgen); 56*91f16700Schasinglulu } 57*91f16700Schasinglulu 58*91f16700Schasinglulu /******************************************************************************* 59*91f16700Schasinglulu * This function copies at most n bytes from the element referred by c into buf. 60*91f16700Schasinglulu ******************************************************************************/ 61*91f16700Schasinglulu static int rootread(chan_t *channel, void *buf, int size) 62*91f16700Schasinglulu { 63*91f16700Schasinglulu const dirtab_t *dp; 64*91f16700Schasinglulu dir_t *dir; 65*91f16700Schasinglulu 66*91f16700Schasinglulu if ((channel->qid & CHDIR) != 0) { 67*91f16700Schasinglulu if (size < sizeof(dir_t)) { 68*91f16700Schasinglulu return -1; 69*91f16700Schasinglulu } 70*91f16700Schasinglulu 71*91f16700Schasinglulu dir = buf; 72*91f16700Schasinglulu return dirread(channel, dir, NULL, 0, rootgen); 73*91f16700Schasinglulu } 74*91f16700Schasinglulu 75*91f16700Schasinglulu /* Only makes sense when using debug language */ 76*91f16700Schasinglulu assert(channel->qid != DEV_ROOT_QBLOBCTL); 77*91f16700Schasinglulu 78*91f16700Schasinglulu dp = &blobtab[channel->qid - DEV_ROOT_QBLOBCTL]; 79*91f16700Schasinglulu return buf_to_channel(channel, buf, dp->data, size, dp->length); 80*91f16700Schasinglulu } 81*91f16700Schasinglulu 82*91f16700Schasinglulu static int rootstat(chan_t *channel, const char *file, dir_t *dir) 83*91f16700Schasinglulu { 84*91f16700Schasinglulu return devstat(channel, file, dir, NULL, 0, rootgen); 85*91f16700Schasinglulu } 86*91f16700Schasinglulu 87*91f16700Schasinglulu const dev_t rootdevtab = { 88*91f16700Schasinglulu .id = '/', 89*91f16700Schasinglulu .stat = rootstat, 90*91f16700Schasinglulu .clone = devclone, 91*91f16700Schasinglulu .attach = devattach, 92*91f16700Schasinglulu .walk = rootwalk, 93*91f16700Schasinglulu .read = rootread, 94*91f16700Schasinglulu .write = deverrwrite, 95*91f16700Schasinglulu .mount = deverrmount, 96*91f16700Schasinglulu .seek = devseek 97*91f16700Schasinglulu }; 98