^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <soc/tegra/bpmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <soc/tegra/bpmp-abi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static DEFINE_MUTEX(bpmp_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct seqbuf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) size_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static void seqbuf_init(struct seqbuf *seqbuf, void *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) seqbuf->buf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) seqbuf->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) seqbuf->pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static size_t seqbuf_avail(struct seqbuf *seqbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return seqbuf->pos < seqbuf->size ? seqbuf->size - seqbuf->pos : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static size_t seqbuf_status(struct seqbuf *seqbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return seqbuf->pos <= seqbuf->size ? 0 : -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static int seqbuf_eof(struct seqbuf *seqbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return seqbuf->pos >= seqbuf->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int seqbuf_read(struct seqbuf *seqbuf, void *buf, size_t nbyte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) nbyte = min(nbyte, seqbuf_avail(seqbuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) memcpy(buf, seqbuf->buf + seqbuf->pos, nbyte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) seqbuf->pos += nbyte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return seqbuf_status(seqbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int seqbuf_read_u32(struct seqbuf *seqbuf, uint32_t *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) err = seqbuf_read(seqbuf, v, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *v = le32_to_cpu(*v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int seqbuf_read_str(struct seqbuf *seqbuf, const char **str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *str = seqbuf->buf + seqbuf->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) seqbuf->pos += strnlen(*str, seqbuf_avail(seqbuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) seqbuf->pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return seqbuf_status(seqbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) seqbuf->pos += offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* map filename in Linux debugfs to corresponding entry in BPMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static const char *get_filename(struct tegra_bpmp *bpmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const struct file *file, char *buf, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) char root_path_buf[512];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) const char *root_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) size_t root_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) root_path = dentry_path(bpmp->debugfs_mirror, root_path_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) sizeof(root_path_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (IS_ERR(root_path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) root_len = strlen(root_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) filename = dentry_path(file->f_path.dentry, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (IS_ERR(filename))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (strlen(filename) < root_len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) strncmp(filename, root_path, root_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) filename += root_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int mrq_debug_open(struct tegra_bpmp *bpmp, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) uint32_t *fd, uint32_t *len, bool write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct mrq_debug_request req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .cmd = cpu_to_le32(write ? CMD_DEBUG_OPEN_WO : CMD_DEBUG_OPEN_RO),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct mrq_debug_response resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct tegra_bpmp_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .mrq = MRQ_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .tx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .data = &req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .size = sizeof(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .rx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .data = &resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .size = sizeof(resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ssize_t sz_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) sz_name = strscpy(req.fop.name, name, sizeof(req.fop.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (sz_name < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) pr_err("File name too large: %s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) err = tegra_bpmp_transfer(bpmp, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) else if (msg.rx.ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) *len = resp.fop.datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) *fd = resp.fop.fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int mrq_debug_close(struct tegra_bpmp *bpmp, uint32_t fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct mrq_debug_request req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .cmd = cpu_to_le32(CMD_DEBUG_CLOSE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .frd = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .fd = fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct mrq_debug_response resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct tegra_bpmp_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .mrq = MRQ_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .tx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .data = &req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .size = sizeof(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .rx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .data = &resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .size = sizeof(resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) err = tegra_bpmp_transfer(bpmp, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) else if (msg.rx.ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int mrq_debug_read(struct tegra_bpmp *bpmp, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) char *data, size_t sz_data, uint32_t *nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct mrq_debug_request req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .cmd = cpu_to_le32(CMD_DEBUG_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct mrq_debug_response resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct tegra_bpmp_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .mrq = MRQ_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .tx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .data = &req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .size = sizeof(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .rx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .data = &resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .size = sizeof(resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) uint32_t fd = 0, len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int remaining, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) mutex_lock(&bpmp_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) err = mrq_debug_open(bpmp, name, &fd, &len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (len > sz_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) err = -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) goto close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) req.frd.fd = fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) remaining = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) while (remaining > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) err = tegra_bpmp_transfer(bpmp, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) goto close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) } else if (msg.rx.ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) goto close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (resp.frd.readlen > remaining) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) pr_err("%s: read data length invalid\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) goto close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) memcpy(data, resp.frd.data, resp.frd.readlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) data += resp.frd.readlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) remaining -= resp.frd.readlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) *nbytes = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) err = mrq_debug_close(bpmp, fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) mutex_unlock(&bpmp_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int mrq_debug_write(struct tegra_bpmp *bpmp, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) uint8_t *data, size_t sz_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct mrq_debug_request req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .cmd = cpu_to_le32(CMD_DEBUG_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct mrq_debug_response resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct tegra_bpmp_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .mrq = MRQ_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .tx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .data = &req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .size = sizeof(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .rx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .data = &resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .size = sizeof(resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) uint32_t fd = 0, len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) size_t remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) mutex_lock(&bpmp_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) err = mrq_debug_open(bpmp, name, &fd, &len, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (sz_data > len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) goto close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) req.fwr.fd = fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) remaining = sz_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) while (remaining > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) len = min(remaining, sizeof(req.fwr.data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) memcpy(req.fwr.data, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) req.fwr.datalen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) err = tegra_bpmp_transfer(bpmp, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) goto close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) } else if (msg.rx.ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) goto close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) data += req.fwr.datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) remaining -= req.fwr.datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) err = mrq_debug_close(bpmp, fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) mutex_unlock(&bpmp_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static int bpmp_debug_show(struct seq_file *m, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct file *file = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct tegra_bpmp *bpmp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) char *databuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) char fnamebuf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) uint32_t nbytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) len = seq_get_buf(m, &databuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (!databuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) filename = get_filename(bpmp, file, fnamebuf, sizeof(fnamebuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (!filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) err = mrq_debug_read(bpmp, filename, databuf, len, &nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) seq_commit(m, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) size_t count, loff_t *f_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct tegra_bpmp *bpmp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) char *databuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) char fnamebuf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) ssize_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) filename = get_filename(bpmp, file, fnamebuf, sizeof(fnamebuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (!filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) databuf = kmalloc(count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (!databuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (copy_from_user(databuf, buf, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) goto free_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) err = mrq_debug_write(bpmp, filename, databuf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) free_ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) kfree(databuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return err ?: count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static int bpmp_debug_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return single_open_size(file, bpmp_debug_show, file, SZ_256K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static const struct file_operations bpmp_debug_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) .open = bpmp_debug_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .write = bpmp_debug_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static int bpmp_populate_debugfs_inband(struct tegra_bpmp *bpmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) char *ppath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) const size_t pathlen = SZ_256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) const size_t bufsize = SZ_16K;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) uint32_t dsize, attrs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct seqbuf seqbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) char *buf, *pathbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!bpmp || !parent || !ppath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) buf = kmalloc(bufsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) pathbuf = kzalloc(pathlen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (!pathbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) err = mrq_debug_read(bpmp, ppath, buf, bufsize, &dsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) seqbuf_init(&seqbuf, buf, dsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) while (!seqbuf_eof(&seqbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) err = seqbuf_read_u32(&seqbuf, &attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) err = seqbuf_read_str(&seqbuf, &name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (attrs & DEBUGFS_S_ISDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) dentry = debugfs_create_dir(name, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) err = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) len = snprintf(pathbuf, pathlen, "%s%s/", ppath, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (len >= pathlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) err = bpmp_populate_debugfs_inband(bpmp, dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) pathbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) mode = attrs & DEBUGFS_S_IRUSR ? 0400 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) mode |= attrs & DEBUGFS_S_IWUSR ? 0200 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) dentry = debugfs_create_file(name, mode, parent, bpmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) &bpmp_debug_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (!dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) kfree(pathbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static int mrq_debugfs_read(struct tegra_bpmp *bpmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) dma_addr_t name, size_t sz_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) dma_addr_t data, size_t sz_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) size_t *nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct mrq_debugfs_request req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) .cmd = cpu_to_le32(CMD_DEBUGFS_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .fop = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .fnameaddr = cpu_to_le32((uint32_t)name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) .fnamelen = cpu_to_le32((uint32_t)sz_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) .dataaddr = cpu_to_le32((uint32_t)data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) .datalen = cpu_to_le32((uint32_t)sz_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct mrq_debugfs_response resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct tegra_bpmp_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) .mrq = MRQ_DEBUGFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) .tx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) .data = &req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) .size = sizeof(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) .rx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) .data = &resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) .size = sizeof(resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) err = tegra_bpmp_transfer(bpmp, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) else if (msg.rx.ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) *nbytes = (size_t)resp.fop.nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static int mrq_debugfs_write(struct tegra_bpmp *bpmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) dma_addr_t name, size_t sz_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) dma_addr_t data, size_t sz_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) const struct mrq_debugfs_request req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) .cmd = cpu_to_le32(CMD_DEBUGFS_WRITE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) .fop = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) .fnameaddr = cpu_to_le32((uint32_t)name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) .fnamelen = cpu_to_le32((uint32_t)sz_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) .dataaddr = cpu_to_le32((uint32_t)data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) .datalen = cpu_to_le32((uint32_t)sz_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct tegra_bpmp_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) .mrq = MRQ_DEBUGFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) .tx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) .data = &req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) .size = sizeof(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return tegra_bpmp_transfer(bpmp, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static int mrq_debugfs_dumpdir(struct tegra_bpmp *bpmp, dma_addr_t addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) size_t size, size_t *nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) const struct mrq_debugfs_request req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) .cmd = cpu_to_le32(CMD_DEBUGFS_DUMPDIR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) .dumpdir = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) .dataaddr = cpu_to_le32((uint32_t)addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) .datalen = cpu_to_le32((uint32_t)size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct mrq_debugfs_response resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct tegra_bpmp_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) .mrq = MRQ_DEBUGFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) .tx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) .data = &req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) .size = sizeof(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) .rx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) .data = &resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .size = sizeof(resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) err = tegra_bpmp_transfer(bpmp, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) else if (msg.rx.ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) *nbytes = (size_t)resp.dumpdir.nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) static int debugfs_show(struct seq_file *m, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct file *file = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct tegra_bpmp *bpmp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) const size_t datasize = m->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) const size_t namesize = SZ_256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) void *datavirt, *namevirt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) dma_addr_t dataphys, namephys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) char buf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) size_t len, nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) filename = get_filename(bpmp, file, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) namevirt = dma_alloc_coherent(bpmp->dev, namesize, &namephys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) GFP_KERNEL | GFP_DMA32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (!namevirt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) datavirt = dma_alloc_coherent(bpmp->dev, datasize, &dataphys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) GFP_KERNEL | GFP_DMA32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (!datavirt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) goto free_namebuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) len = strlen(filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) strncpy(namevirt, filename, namesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) err = mrq_debugfs_read(bpmp, namephys, len, dataphys, datasize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) &nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) seq_write(m, datavirt, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) dma_free_coherent(bpmp->dev, datasize, datavirt, dataphys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) free_namebuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) dma_free_coherent(bpmp->dev, namesize, namevirt, namephys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static int debugfs_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return single_open_size(file, debugfs_show, file, SZ_128K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static ssize_t debugfs_store(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) size_t count, loff_t *f_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct tegra_bpmp *bpmp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) const size_t datasize = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) const size_t namesize = SZ_256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) void *datavirt, *namevirt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) dma_addr_t dataphys, namephys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) char fnamebuf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) filename = get_filename(bpmp, file, fnamebuf, sizeof(fnamebuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (!filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) namevirt = dma_alloc_coherent(bpmp->dev, namesize, &namephys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) GFP_KERNEL | GFP_DMA32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (!namevirt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) datavirt = dma_alloc_coherent(bpmp->dev, datasize, &dataphys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) GFP_KERNEL | GFP_DMA32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (!datavirt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) goto free_namebuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) len = strlen(filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) strncpy(namevirt, filename, namesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (copy_from_user(datavirt, buf, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) goto free_databuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) err = mrq_debugfs_write(bpmp, namephys, len, dataphys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) free_databuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) dma_free_coherent(bpmp->dev, datasize, datavirt, dataphys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) free_namebuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) dma_free_coherent(bpmp->dev, namesize, namevirt, namephys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return err ?: count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static const struct file_operations debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) .open = debugfs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) .write = debugfs_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) .release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static int bpmp_populate_dir(struct tegra_bpmp *bpmp, struct seqbuf *seqbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct dentry *parent, uint32_t depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) uint32_t d, t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) while (!seqbuf_eof(seqbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) err = seqbuf_read_u32(seqbuf, &d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (d < depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) seqbuf_seek(seqbuf, -4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) /* go up a level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) } else if (d != depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /* malformed data received from BPMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) err = seqbuf_read_u32(seqbuf, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) err = seqbuf_read_str(seqbuf, &name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (t & DEBUGFS_S_ISDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) dentry = debugfs_create_dir(name, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) err = bpmp_populate_dir(bpmp, seqbuf, dentry, depth+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) mode = t & DEBUGFS_S_IRUSR ? S_IRUSR : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) mode |= t & DEBUGFS_S_IWUSR ? S_IWUSR : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) dentry = debugfs_create_file(name, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) parent, bpmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) &debugfs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static int bpmp_populate_debugfs_shmem(struct tegra_bpmp *bpmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) struct seqbuf seqbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) const size_t sz = SZ_512K;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) dma_addr_t phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) size_t nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) void *virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) virt = dma_alloc_coherent(bpmp->dev, sz, &phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) GFP_KERNEL | GFP_DMA32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (!virt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) err = mrq_debugfs_dumpdir(bpmp, phys, sz, &nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) } else if (nbytes > sz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) seqbuf_init(&seqbuf, virt, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) err = bpmp_populate_dir(bpmp, &seqbuf, bpmp->debugfs_mirror, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) dma_free_coherent(bpmp->dev, sz, virt, phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct dentry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) bool inband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) inband = tegra_bpmp_mrq_is_supported(bpmp, MRQ_DEBUG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (!inband && !tegra_bpmp_mrq_is_supported(bpmp, MRQ_DEBUGFS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) root = debugfs_create_dir("bpmp", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) bpmp->debugfs_mirror = debugfs_create_dir("debug", root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (!bpmp->debugfs_mirror) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (inband)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) err = bpmp_populate_debugfs_inband(bpmp, bpmp->debugfs_mirror,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) "/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) err = bpmp_populate_debugfs_shmem(bpmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) debugfs_remove_recursive(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }