Casey Chen | cfa2835 | 2018-04-21 01:03:02 -0700 | [diff] [blame] | 1 | /* |
Subhash Kumar Katnpally | b830478 | 2018-10-11 11:46:13 +0530 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. |
Casey Chen | cfa2835 | 2018-04-21 01:03:02 -0700 | [diff] [blame] | 3 | * |
| 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 Katnpally | b830478 | 2018-10-11 11:46:13 +0530 | [diff] [blame] | 32 | #define NSS_MEMINFO_RESERVE_AREA_UTCM_SHARED_MAP_MAGIC 0x9530 /* Magic at the beginning of UTCM_SHARED reserved space */ |
Casey Chen | cfa2835 | 2018-04-21 01:03:02 -0700 | [diff] [blame] | 33 | #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 Katnpally | b830478 | 2018-10-11 11:46:13 +0530 | [diff] [blame] | 36 | #define NSS_MEMINFO_POISON 0x95 /* Invalid kernel memory address assigned for non mapable mem types */ |
Casey Chen | cfa2835 | 2018-04-21 01:03:02 -0700 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Memory types available |
| 40 | */ |
| 41 | enum nss_meminfo_memtype { |
| 42 | NSS_MEMINFO_MEMTYPE_IMEM, /* NSS-IMEM also called TCM */ |
| 43 | NSS_MEMINFO_MEMTYPE_SDRAM, /* SDRAM also called DDR */ |
Guojun Jin | 6ed3232 | 2019-09-11 12:32:24 -0700 | [diff] [blame^] | 44 | NSS_MEMINFO_MEMTYPE_UTCM_SHARED, /* UTCM memory allocated for DMA objects */ |
| 45 | NSS_MEMINFO_MEMTYPE_INFO, /* Exchange information during boot up */ |
Casey Chen | cfa2835 | 2018-04-21 01:03:02 -0700 | [diff] [blame] | 46 | NSS_MEMINFO_MEMTYPE_MAX |
| 47 | }; |
| 48 | |
| 49 | /* |
| 50 | * Memory request |
| 51 | * Firmware package defines each request asking host to feed the request. |
| 52 | */ |
| 53 | struct nss_meminfo_request { |
| 54 | uint16_t magic; /* Request magic */ |
| 55 | char name[NSS_MEMINFO_BLOCK_NAME_MAXLEN]; /* Memory block name */ |
| 56 | uint16_t memtype_default; /* Memory type requested */ |
| 57 | uint16_t memtype_user; /* User-defined memory type */ |
| 58 | uint32_t alignment; /* Alignment requirement */ |
| 59 | uint32_t size; /* Size requested */ |
| 60 | uint32_t addr; /* Memory block address got from host */ |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * Memory map |
| 65 | * It starts with a magic then an array of memory request and end with a checksum. |
| 66 | * Firmware creates the map for host to parse. |
| 67 | */ |
| 68 | struct nss_meminfo_map { |
| 69 | uint32_t *start; /* Start address */ |
| 70 | uint32_t num_requests; /* Number of requests */ |
| 71 | struct nss_meminfo_request *requests; /* Start of Request array */ |
| 72 | }; |
| 73 | |
| 74 | /* |
| 75 | * Memory block |
| 76 | * Block node for each request. |
| 77 | */ |
| 78 | struct nss_meminfo_block { |
| 79 | struct nss_meminfo_block *next; /* Next block in the same list */ |
| 80 | uint32_t index; /* Index to request array */ |
| 81 | uint32_t size; /* Size of memory block */ |
| 82 | uint32_t dma_addr; /* DMA address */ |
| 83 | unsigned long kern_addr; /* Kernel address */ |
| 84 | }; |
| 85 | |
| 86 | /* |
| 87 | * Memory block list |
| 88 | * List of block node of same memory type. |
| 89 | */ |
| 90 | struct nss_meminfo_block_list { |
| 91 | enum nss_meminfo_memtype memtype; /* memory type */ |
| 92 | uint32_t num_blks; /* Number of blocks */ |
| 93 | uint32_t total_size; /* Size of all memory blocks in this list */ |
| 94 | struct nss_meminfo_block *head; /* list head */ |
| 95 | }; |
| 96 | |
| 97 | /* |
| 98 | * H2N/N2H rings information |
| 99 | */ |
| 100 | struct nss_meminfo_n2h_h2n_info { |
| 101 | enum nss_meminfo_memtype memtype; /* Memory type */ |
| 102 | uint32_t total_size; /* Total size */ |
| 103 | uint32_t dma_addr; /* DMA address */ |
| 104 | unsigned long kern_addr; /* Kernel address */ |
| 105 | }; |
| 106 | |
| 107 | /* |
| 108 | * Memory context |
| 109 | */ |
| 110 | struct nss_meminfo_ctx { |
| 111 | struct nss_meminfo_n2h_h2n_info n2h_info; /* N2H rings info*/ |
| 112 | struct nss_meminfo_n2h_h2n_info h2n_info; /* H2N rings info */ |
| 113 | uint32_t imem_head; /* IMEM start address */ |
| 114 | uint32_t imem_end; /* IMEM end address */ |
| 115 | uint32_t imem_tail; /* IMEM data end */ |
Subhash Kumar Katnpally | b830478 | 2018-10-11 11:46:13 +0530 | [diff] [blame] | 116 | uint32_t utcm_shared_head; /* UTCM_SHARED start address */ |
| 117 | uint32_t utcm_shared_end; /* UTCM_SHARED end address */ |
| 118 | uint32_t utcm_shared_tail; /* UTCM_SHARED data end */ |
Casey Chen | cfa2835 | 2018-04-21 01:03:02 -0700 | [diff] [blame] | 119 | struct nss_if_mem_map *if_map; /* nss_if_mem_map_inst virtual address */ |
| 120 | uint32_t if_map_dma; /* nss_if_mem_map_inst physical address */ |
| 121 | enum nss_meminfo_memtype if_map_memtype; /* Memory type for nss_if_mem_map */ |
Cemil Coskun | 5f51db5 | 2018-05-07 17:15:37 -0700 | [diff] [blame] | 122 | struct nss_log_descriptor *logbuffer; /* nss_logbuffer virtual address */ |
| 123 | uint32_t logbuffer_dma; /* nss_logbuffer physical address */ |
| 124 | enum nss_meminfo_memtype logbuffer_memtype; /* Memory type for logbuffer */ |
Cemil Coskun | 3bb2051 | 2018-07-24 10:42:25 -0700 | [diff] [blame] | 125 | uint32_t c2c_start_dma; /* nss_c2c start physical address */ |
| 126 | enum nss_meminfo_memtype c2c_start_memtype; /* Memory type for c2c_start */ |
Casey Chen | cfa2835 | 2018-04-21 01:03:02 -0700 | [diff] [blame] | 127 | struct nss_meminfo_map meminfo_map; /* Meminfo map */ |
| 128 | struct nss_meminfo_block_list block_lists[NSS_MEMINFO_MEMTYPE_MAX]; |
| 129 | /* Block lists for each memory type */ |
| 130 | }; |
| 131 | |
| 132 | bool nss_meminfo_init(struct nss_ctx_instance *nss_ctx); |
| 133 | #endif |