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