/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2016-2018, 2020, The Linux Foundation. All rights reserved. * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
*/
/** * struct entry_header: header for each entry in cmddb * * @id: resource's identifier * @priority: unused * @addr: the address of the resource * @len: length of the data * @offset: offset from :@data_offset, start of the data
*/ struct entry_header {
u8 id[8];
__le32 priority[NUM_PRIORITY];
__le32 addr;
__le16 len;
__le16 offset;
};
/** * struct rsc_hdr: resource header information * * @slv_id: id for the resource * @header_offset: entry's header at offset from the end of the cmd_db_header * @data_offset: entry's data at offset from the end of the cmd_db_header * @cnt: number of entries for HW type * @version: MSB is major, LSB is minor * @reserved: reserved for future use.
*/ struct rsc_hdr {
__le16 slv_id;
__le16 header_offset;
__le16 data_offset;
__le16 cnt;
__le16 version;
__le16 reserved[3];
};
/** * struct cmd_db_header: The DB header information * * @version: The cmd db version * @magic: constant expected in the database * @header: array of resources * @checksum: checksum for the header. Unused. * @reserved: reserved memory * @data: driver specific data
*/ struct cmd_db_header {
__le32 version;
u8 magic[4]; struct rsc_hdr header[MAX_SLV_ID];
__le32 checksum;
__le32 reserved;
u8 data[];
};
/** * DOC: Description of the Command DB database. * * At the start of the command DB memory is the cmd_db_header structure. * The cmd_db_header holds the version, checksum, magic key as well as an * array for header for each slave (depicted by the rsc_header). Each h/w * based accelerator is a 'slave' (shared resource) and has slave id indicating * the type of accelerator. The rsc_header is the header for such individual * slaves of a given type. The entries for each of these slaves begin at the * rsc_hdr.header_offset. In addition each slave could have auxiliary data * that may be needed by the driver. The data for the slave starts at the * entry_header.offset to the location pointed to by the rsc_hdr.data_offset. * * Drivers have a stringified key to a slave/resource. They can query the slave * information and get the slave id and the auxiliary data and the length of the * data. Using this information, they can format the request to be sent to the * h/w accelerator and request a resource state.
*/
/** * cmd_db_ready - Indicates if command DB is available * * Return: 0 on success, errno otherwise
*/ int cmd_db_ready(void)
{ if (cmd_db_header == NULL) return -EPROBE_DEFER; elseif (!cmd_db_magic_matches(cmd_db_header)) return -EINVAL;
for (i = 0; i < MAX_SLV_ID; i++) {
rsc_hdr = &cmd_db_header->header[i]; if (!rsc_hdr->slv_id) break;
ent = rsc_to_entry_header(rsc_hdr); for (j = 0; j < le16_to_cpu(rsc_hdr->cnt); j++, ent++) { if (memcmp(ent->id, query, sizeof(ent->id)) == 0) { if (eh)
*eh = ent; if (rh)
*rh = rsc_hdr; return 0;
}
}
}
return -ENODEV;
}
/** * cmd_db_read_addr() - Query command db for resource id address. * * @id: resource id to query for address * * Return: resource address on success, 0 on error * * This is used to retrieve resource address based on resource * id.
*/
u32 cmd_db_read_addr(constchar *id)
{ int ret; conststruct entry_header *ent;
ret = cmd_db_get_header(id, &ent, NULL);
return ret < 0 ? 0 : le32_to_cpu(ent->addr);
}
EXPORT_SYMBOL_GPL(cmd_db_read_addr);
/** * cmd_db_read_aux_data() - Query command db for aux data. * * @id: Resource to retrieve AUX Data on * @len: size of data buffer returned * * Return: pointer to data on success, error pointer otherwise
*/ constvoid *cmd_db_read_aux_data(constchar *id, size_t *len)
{ int ret; conststruct entry_header *ent; conststruct rsc_hdr *rsc_hdr;
ret = cmd_db_get_header(id, &ent, &rsc_hdr); if (ret) return ERR_PTR(ret);
/** * cmd_db_match_resource_addr() - Compare if both Resource addresses are same * * @addr1: Resource address to compare * @addr2: Resource address to compare * * Return: true if two addresses refer to the same resource, false otherwise
*/ bool cmd_db_match_resource_addr(u32 addr1, u32 addr2)
{ /* * Each RPMh VRM accelerator resource has 3 or 4 contiguous 4-byte * aligned addresses associated with it. Ignore the offset to check * for VRM requests.
*/ if (addr1 == addr2) returntrue; elseif (SLAVE_ID(addr1) == CMD_DB_HW_VRM && VRM_ADDR(addr1) == VRM_ADDR(addr2)) returntrue;
/** * cmd_db_read_slave_id - Get the slave ID for a given resource address * * @id: Resource id to query the DB for version * * Return: cmd_db_hw_type enum on success, CMD_DB_HW_INVALID on error
*/ enum cmd_db_hw_type cmd_db_read_slave_id(constchar *id)
{ int ret; conststruct entry_header *ent;
u32 addr;
ret = cmd_db_get_header(id, &ent, NULL); if (ret < 0) return CMD_DB_HW_INVALID;
for (i = 0; i < MAX_SLV_ID; i++) {
rsc = &cmd_db_header->header[i]; if (!rsc->slv_id) break;
switch (le16_to_cpu(rsc->slv_id)) { case CMD_DB_HW_ARC:
name = "ARC"; break; case CMD_DB_HW_VRM:
name = "VRM"; break; case CMD_DB_HW_BCM:
name = "BCM"; break; default:
name = "Unknown"; break;
}
version = le16_to_cpu(rsc->version);
major = version >> 8;
minor = version;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.