Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Copyright (c) 2016-2018, 2020, The Linux Foundation. All rights reserved. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/of_reserved_mem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <soc/qcom/cmd-db.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define NUM_PRIORITY		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define MAX_SLV_ID		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define SLAVE_ID_MASK		0x7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define SLAVE_ID_SHIFT		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * struct entry_header: header for each entry in cmddb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @id: resource's identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @priority: unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @addr: the address of the resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * @len: length of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * @offset: offset from :@data_offset, start of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) struct entry_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	u8 id[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	__le32 priority[NUM_PRIORITY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	__le32 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	__le16 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	__le16 offset;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * struct rsc_hdr: resource header information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * @slv_id: id for the resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * @header_offset: entry's header at offset from the end of the cmd_db_header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * @data_offset: entry's data at offset from the end of the cmd_db_header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * @cnt: number of entries for HW type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * @version: MSB is major, LSB is minor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @reserved: reserved for future use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) struct rsc_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	__le16 slv_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	__le16 header_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	__le16 data_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	__le16 cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	__le16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	__le16 reserved[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * struct cmd_db_header: The DB header information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @version: The cmd db version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * @magic: constant expected in the database
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * @header: array of resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * @checksum: checksum for the header. Unused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * @reserved: reserved memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * @data: driver specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) struct cmd_db_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	__le32 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	u8 magic[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct rsc_hdr header[MAX_SLV_ID];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	__le32 checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	__le32 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	u8 data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * DOC: Description of the Command DB database.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * At the start of the command DB memory is the cmd_db_header structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * The cmd_db_header holds the version, checksum, magic key as well as an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * array for header for each slave (depicted by the rsc_header). Each h/w
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * based accelerator is a 'slave' (shared resource) and has slave id indicating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * the type of accelerator. The rsc_header is the header for such individual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * slaves of a given type. The entries for each of these slaves begin at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * rsc_hdr.header_offset. In addition each slave could have auxiliary data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * that may be needed by the driver. The data for the slave starts at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * entry_header.offset to the location pointed to by the rsc_hdr.data_offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * Drivers have a stringified key to a slave/resource. They can query the slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * information and get the slave id and the auxiliary data and the length of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * data. Using this information, they can format the request to be sent to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * h/w accelerator and request a resource state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static const u8 CMD_DB_MAGIC[] = { 0xdb, 0x30, 0x03, 0x0c };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static bool cmd_db_magic_matches(const struct cmd_db_header *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	const u8 *magic = header->magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return memcmp(magic, CMD_DB_MAGIC, ARRAY_SIZE(CMD_DB_MAGIC)) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct cmd_db_header *cmd_db_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static inline const void *rsc_to_entry_header(const struct rsc_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u16 offset = le16_to_cpu(hdr->header_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return cmd_db_header->data + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static inline void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) rsc_offset(const struct rsc_hdr *hdr, const struct entry_header *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	u16 offset = le16_to_cpu(hdr->data_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	u16 loffset = le16_to_cpu(ent->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return cmd_db_header->data + offset + loffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * cmd_db_ready - Indicates if command DB is available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * Return: 0 on success, errno otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int cmd_db_ready(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (cmd_db_header == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	else if (!cmd_db_magic_matches(cmd_db_header))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) EXPORT_SYMBOL(cmd_db_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int cmd_db_get_header(const char *id, const struct entry_header **eh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			     const struct rsc_hdr **rh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	const struct rsc_hdr *rsc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	const struct entry_header *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	int ret, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u8 query[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	ret = cmd_db_ready();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/* Pad out query string to same length as in DB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	strncpy(query, id, sizeof(query));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	for (i = 0; i < MAX_SLV_ID; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		rsc_hdr = &cmd_db_header->header[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		if (!rsc_hdr->slv_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		ent = rsc_to_entry_header(rsc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		for (j = 0; j < le16_to_cpu(rsc_hdr->cnt); j++, ent++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			if (memcmp(ent->id, query, sizeof(ent->id)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				if (eh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 					*eh = ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				if (rh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 					*rh = rsc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * cmd_db_read_addr() - Query command db for resource id address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * @id: resource id to query for address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * Return: resource address on success, 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * This is used to retrieve resource address based on resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) u32 cmd_db_read_addr(const char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	const struct entry_header *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	ret = cmd_db_get_header(id, &ent, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return ret < 0 ? 0 : le32_to_cpu(ent->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) EXPORT_SYMBOL(cmd_db_read_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * cmd_db_read_aux_data() - Query command db for aux data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  *  @id: Resource to retrieve AUX Data on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  *  @len: size of data buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  *  Return: pointer to data on success, error pointer otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) const void *cmd_db_read_aux_data(const char *id, size_t *len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	const struct entry_header *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	const struct rsc_hdr *rsc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	ret = cmd_db_get_header(id, &ent, &rsc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		*len = le16_to_cpu(ent->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return rsc_offset(rsc_hdr, ent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) EXPORT_SYMBOL(cmd_db_read_aux_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * cmd_db_read_slave_id - Get the slave ID for a given resource address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * @id: Resource id to query the DB for version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * Return: cmd_db_hw_type enum on success, CMD_DB_HW_INVALID on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) enum cmd_db_hw_type cmd_db_read_slave_id(const char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	const struct entry_header *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	u32 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	ret = cmd_db_get_header(id, &ent, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return CMD_DB_HW_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	addr = le32_to_cpu(ent->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return (addr >> SLAVE_ID_SHIFT) & SLAVE_ID_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) EXPORT_SYMBOL(cmd_db_read_slave_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int cmd_db_debugfs_dump(struct seq_file *seq, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	const struct rsc_hdr *rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	const struct entry_header *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	u16 len, version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	u8 major, minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	seq_puts(seq, "Command DB DUMP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	for (i = 0; i < MAX_SLV_ID; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		rsc = &cmd_db_header->header[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		if (!rsc->slv_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		switch (le16_to_cpu(rsc->slv_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		case CMD_DB_HW_ARC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			name = "ARC";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		case CMD_DB_HW_VRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			name = "VRM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		case CMD_DB_HW_BCM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			name = "BCM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			name = "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		version = le16_to_cpu(rsc->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		major = version >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		minor = version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		seq_printf(seq, "Slave %s (v%u.%u)\n", name, major, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		seq_puts(seq, "-------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		ent = rsc_to_entry_header(rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		for (j = 0; j < le16_to_cpu(rsc->cnt); j++, ent++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			seq_printf(seq, "0x%05x: %*pEp", le32_to_cpu(ent->addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				   (int)sizeof(ent->id), ent->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			len = le16_to_cpu(ent->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			if (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 				seq_printf(seq, " [%*ph]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 					   len, rsc_offset(rsc, ent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		}
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static int open_cmd_db_debugfs(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return single_open(file, cmd_db_debugfs_dump, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static const struct file_operations cmd_db_debugfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	.open = open_cmd_db_debugfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static int cmd_db_dev_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct reserved_mem *rmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	rmem = of_reserved_mem_lookup(pdev->dev.of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (!rmem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		dev_err(&pdev->dev, "failed to acquire memory region\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	cmd_db_header = memremap(rmem->base, rmem->size, MEMREMAP_WB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (!cmd_db_header) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		cmd_db_header = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (!cmd_db_magic_matches(cmd_db_header)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		dev_err(&pdev->dev, "Invalid Command DB Magic\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	debugfs_create_file("cmd-db", 0400, NULL, NULL, &cmd_db_debugfs_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static const struct of_device_id cmd_db_match_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	{ .compatible = "qcom,cmd-db" },
^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) MODULE_DEVICE_TABLE(of, cmd_db_match_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static struct platform_driver cmd_db_dev_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	.probe  = cmd_db_dev_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		   .name = "cmd-db",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		   .of_match_table = cmd_db_match_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		   .suppress_bind_attrs = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static int __init cmd_db_device_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	return platform_driver_register(&cmd_db_dev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) arch_initcall(cmd_db_device_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Command DB Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) MODULE_LICENSE("GPL v2");