blob: 0b7f8222a30ffc7eb3c51e8f013b358db4ac3f5a [file] [log] [blame]
Casey Chencfa28352018-04-21 01:03:02 -07001/*
Subhash Kumar Katnpallyb8304782018-10-11 11:46:13 +05302 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
Casey Chencfa28352018-04-21 01:03:02 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/*
18 * nss_meminfo.h
19 * nss meminfo header file.
20 */
21
22#ifndef __NSS_MEMINFO_H
23#define __NSS_MEMINFO_H
24
25#define NSS_MEMINFO_RESERVE_AREA_SIZE 0x1000 /* Size of reserved space in firmware start code aligned to one page */
26#define NSS_MEMINFO_RESERVE_AREA_MAGIC 0x9526 /* Magic at the beginning of reserved space */
27#define NSS_MEMINFO_MAP_START_OFFSET 8 /* Offset of memory map start address in reserved space */
28#define NSS_MEMINFO_MAP_SIZE 0x1000 /* Size of memory map per core aligned to one page */
29#define NSS_MEMINFO_MAP_START_MAGIC 0x9527
30#define NSS_MEMINFO_REQUEST_MAGIC 0X9528
31#define NSS_MEMINFO_MAP_END_MAGIC 0x9529
Subhash Kumar Katnpallyb8304782018-10-11 11:46:13 +053032#define NSS_MEMINFO_RESERVE_AREA_UTCM_SHARED_MAP_MAGIC 0x9530 /* Magic at the beginning of UTCM_SHARED reserved space */
Casey Chencfa28352018-04-21 01:03:02 -070033#define NSS_MEMINFO_BLOCK_NAME_MAXLEN 48
34#define NSS_MEMINFO_MEMTYPE_NAME_MAXLEN 32
35#define NSS_MEMINFO_USER_CONFIG_MAXLEN 1024
Subhash Kumar Katnpallyb8304782018-10-11 11:46:13 +053036#define NSS_MEMINFO_POISON 0x95 /* Invalid kernel memory address assigned for non mapable mem types */
Casey Chencfa28352018-04-21 01:03:02 -070037
38/*
39 * Memory types available
40 */
41enum nss_meminfo_memtype {
42 NSS_MEMINFO_MEMTYPE_IMEM, /* NSS-IMEM also called TCM */
43 NSS_MEMINFO_MEMTYPE_SDRAM, /* SDRAM also called DDR */
Subhash Kumar Katnpallyb8304782018-10-11 11:46:13 +053044 NSS_MEMINFO_MEMTYPE_UTCM_SHARED, /* UTCM memory allocated for DMA objects */
Casey Chencfa28352018-04-21 01:03:02 -070045 NSS_MEMINFO_MEMTYPE_MAX
46};
47
48/*
49 * Memory request
50 * Firmware package defines each request asking host to feed the request.
51 */
52struct nss_meminfo_request {
53 uint16_t magic; /* Request magic */
54 char name[NSS_MEMINFO_BLOCK_NAME_MAXLEN]; /* Memory block name */
55 uint16_t memtype_default; /* Memory type requested */
56 uint16_t memtype_user; /* User-defined memory type */
57 uint32_t alignment; /* Alignment requirement */
58 uint32_t size; /* Size requested */
59 uint32_t addr; /* Memory block address got from host */
60};
61
62/*
63 * Memory map
64 * It starts with a magic then an array of memory request and end with a checksum.
65 * Firmware creates the map for host to parse.
66 */
67struct nss_meminfo_map {
68 uint32_t *start; /* Start address */
69 uint32_t num_requests; /* Number of requests */
70 struct nss_meminfo_request *requests; /* Start of Request array */
71};
72
73/*
74 * Memory block
75 * Block node for each request.
76 */
77struct nss_meminfo_block {
78 struct nss_meminfo_block *next; /* Next block in the same list */
79 uint32_t index; /* Index to request array */
80 uint32_t size; /* Size of memory block */
81 uint32_t dma_addr; /* DMA address */
82 unsigned long kern_addr; /* Kernel address */
83};
84
85/*
86 * Memory block list
87 * List of block node of same memory type.
88 */
89struct nss_meminfo_block_list {
90 enum nss_meminfo_memtype memtype; /* memory type */
91 uint32_t num_blks; /* Number of blocks */
92 uint32_t total_size; /* Size of all memory blocks in this list */
93 struct nss_meminfo_block *head; /* list head */
94};
95
96/*
97 * H2N/N2H rings information
98 */
99struct nss_meminfo_n2h_h2n_info {
100 enum nss_meminfo_memtype memtype; /* Memory type */
101 uint32_t total_size; /* Total size */
102 uint32_t dma_addr; /* DMA address */
103 unsigned long kern_addr; /* Kernel address */
104};
105
106/*
107 * Memory context
108 */
109struct nss_meminfo_ctx {
110 struct nss_meminfo_n2h_h2n_info n2h_info; /* N2H rings info*/
111 struct nss_meminfo_n2h_h2n_info h2n_info; /* H2N rings info */
112 uint32_t imem_head; /* IMEM start address */
113 uint32_t imem_end; /* IMEM end address */
114 uint32_t imem_tail; /* IMEM data end */
Subhash Kumar Katnpallyb8304782018-10-11 11:46:13 +0530115 uint32_t utcm_shared_head; /* UTCM_SHARED start address */
116 uint32_t utcm_shared_end; /* UTCM_SHARED end address */
117 uint32_t utcm_shared_tail; /* UTCM_SHARED data end */
Casey Chencfa28352018-04-21 01:03:02 -0700118 struct nss_if_mem_map *if_map; /* nss_if_mem_map_inst virtual address */
119 uint32_t if_map_dma; /* nss_if_mem_map_inst physical address */
120 enum nss_meminfo_memtype if_map_memtype; /* Memory type for nss_if_mem_map */
Cemil Coskun5f51db52018-05-07 17:15:37 -0700121 struct nss_log_descriptor *logbuffer; /* nss_logbuffer virtual address */
122 uint32_t logbuffer_dma; /* nss_logbuffer physical address */
123 enum nss_meminfo_memtype logbuffer_memtype; /* Memory type for logbuffer */
Cemil Coskun3bb20512018-07-24 10:42:25 -0700124 uint32_t c2c_start_dma; /* nss_c2c start physical address */
125 enum nss_meminfo_memtype c2c_start_memtype; /* Memory type for c2c_start */
Casey Chencfa28352018-04-21 01:03:02 -0700126 struct nss_meminfo_map meminfo_map; /* Meminfo map */
127 struct nss_meminfo_block_list block_lists[NSS_MEMINFO_MEMTYPE_MAX];
128 /* Block lists for each memory type */
129};
130
131bool nss_meminfo_init(struct nss_ctx_instance *nss_ctx);
132#endif