Avaneesh Kumar Dwivedi | 7b506d2 | 2017-03-17 16:41:13 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2010-2017, The Linux Foundation. All rights reserved. |
Kyle Yan | e45fa02 | 2016-08-29 11:40:26 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #ifndef __MSM_PERIPHERAL_LOADER_H |
| 13 | #define __MSM_PERIPHERAL_LOADER_H |
| 14 | |
| 15 | struct device; |
| 16 | struct module; |
| 17 | struct pil_priv; |
| 18 | |
| 19 | /** |
| 20 | * struct pil_desc - PIL descriptor |
| 21 | * @name: string used for pil_get() |
| 22 | * @fw_name: firmware name |
| 23 | * @dev: parent device |
| 24 | * @ops: callback functions |
| 25 | * @owner: module the descriptor belongs to |
| 26 | * @proxy_timeout: delay in ms until proxy vote is removed |
| 27 | * @flags: bitfield for image flags |
| 28 | * @priv: DON'T USE - internal only |
| 29 | * @attrs: DMA attributes to be used during dma allocation. |
| 30 | * @proxy_unvote_irq: IRQ to trigger a proxy unvote. proxy_timeout |
| 31 | * is ignored if this is set. |
| 32 | * @map_fw_mem: Custom function used to map physical address space to virtual. |
| 33 | * This defaults to ioremap if not specified. |
| 34 | * @unmap_fw_mem: Custom function used to undo mapping by map_fw_mem. |
| 35 | * This defaults to iounmap if not specified. |
| 36 | * @shutdown_fail: Set if PIL op for shutting down subsystem fails. |
| 37 | * @modem_ssr: true if modem is restarting, false if booting for first time. |
Avaneesh Kumar Dwivedi | 7b506d2 | 2017-03-17 16:41:13 +0530 | [diff] [blame] | 38 | * @clear_fw_region: Clear fw region on failure in loading. |
Kyle Yan | e45fa02 | 2016-08-29 11:40:26 -0700 | [diff] [blame] | 39 | * @subsys_vmid: memprot id for the subsystem. |
| 40 | */ |
| 41 | struct pil_desc { |
| 42 | const char *name; |
| 43 | const char *fw_name; |
| 44 | struct device *dev; |
| 45 | const struct pil_reset_ops *ops; |
| 46 | struct module *owner; |
| 47 | unsigned long proxy_timeout; |
| 48 | unsigned long flags; |
| 49 | #define PIL_SKIP_ENTRY_CHECK BIT(0) |
| 50 | struct pil_priv *priv; |
| 51 | unsigned long attrs; |
| 52 | unsigned int proxy_unvote_irq; |
| 53 | void * (*map_fw_mem)(phys_addr_t phys, size_t size, void *data); |
| 54 | void (*unmap_fw_mem)(void *virt, size_t size, void *data); |
| 55 | void *map_data; |
| 56 | bool shutdown_fail; |
| 57 | bool modem_ssr; |
Avaneesh Kumar Dwivedi | 7b506d2 | 2017-03-17 16:41:13 +0530 | [diff] [blame] | 58 | bool clear_fw_region; |
Kyle Yan | e45fa02 | 2016-08-29 11:40:26 -0700 | [diff] [blame] | 59 | u32 subsys_vmid; |
| 60 | }; |
| 61 | |
| 62 | /** |
| 63 | * struct pil_image_info - info in IMEM about image and where it is loaded |
| 64 | * @name: name of image (may or may not be NULL terminated) |
| 65 | * @start: indicates physical address where image starts (little endian) |
| 66 | * @size: size of image (little endian) |
| 67 | */ |
| 68 | struct pil_image_info { |
| 69 | char name[8]; |
| 70 | __le64 start; |
| 71 | __le32 size; |
| 72 | } __attribute__((__packed__)); |
| 73 | |
Avaneesh Kumar Dwivedi | ec6d139 | 2017-07-06 21:18:03 +0530 | [diff] [blame] | 74 | #define MAX_NUM_OF_SS 3 |
| 75 | |
| 76 | /** |
| 77 | * struct md_ssr_ss_info - Info in imem about smem ToC |
| 78 | * @md_ss_smem_regions_baseptr: Start physical address of SMEM TOC |
| 79 | * @md_ss_num_of_regions: number of segments that need to be dumped |
| 80 | * @md_ss_encryption_status: status of encryption of segments |
| 81 | * @md_ss_ssr_cause: ssr cause enum |
| 82 | */ |
| 83 | struct md_ssr_ss_info { |
| 84 | u32 md_ss_smem_regions_baseptr; |
| 85 | u8 md_ss_num_of_regions; |
| 86 | u8 md_ss_encryption_status; |
| 87 | u8 md_ss_ssr_cause; |
| 88 | u8 reserved; |
| 89 | }; |
| 90 | |
| 91 | /** |
| 92 | * struct md_ssr_toc - Wrapper of struct md_ssr_ss_info |
| 93 | * @md_ssr_toc_init: flag to indicate to MSS SW about imem init done |
| 94 | * @md_ssr_ss: Instance of struct md_ssr_ss_info for a subsystem |
| 95 | */ |
| 96 | struct md_ssr_toc /* Shared IMEM ToC struct */ |
| 97 | { |
| 98 | u32 md_ssr_toc_init; |
| 99 | struct md_ssr_ss_info md_ssr_ss[MAX_NUM_OF_SS]; |
| 100 | }; |
| 101 | |
Kyle Yan | e45fa02 | 2016-08-29 11:40:26 -0700 | [diff] [blame] | 102 | /** |
| 103 | * struct pil_reset_ops - PIL operations |
| 104 | * @init_image: prepare an image for authentication |
| 105 | * @mem_setup: prepare the image memory region |
| 106 | * @verify_blob: authenticate a program segment, called once for each loadable |
| 107 | * program segment (optional) |
| 108 | * @proxy_vote: make proxy votes before auth_and_reset (optional) |
| 109 | * @auth_and_reset: boot the processor |
| 110 | * @proxy_unvote: remove any proxy votes (optional) |
| 111 | * @deinit_image: restore actions performed in init_image if necessary |
| 112 | * @shutdown: shutdown the processor |
| 113 | */ |
| 114 | struct pil_reset_ops { |
| 115 | int (*init_image)(struct pil_desc *pil, const u8 *metadata, |
| 116 | size_t size); |
| 117 | int (*mem_setup)(struct pil_desc *pil, phys_addr_t addr, size_t size); |
| 118 | int (*verify_blob)(struct pil_desc *pil, phys_addr_t phy_addr, |
| 119 | size_t size); |
| 120 | int (*proxy_vote)(struct pil_desc *pil); |
| 121 | int (*auth_and_reset)(struct pil_desc *pil); |
| 122 | void (*proxy_unvote)(struct pil_desc *pil); |
| 123 | int (*deinit_image)(struct pil_desc *pil); |
| 124 | int (*shutdown)(struct pil_desc *pil); |
| 125 | }; |
| 126 | |
| 127 | #ifdef CONFIG_MSM_PIL |
| 128 | extern int pil_desc_init(struct pil_desc *desc); |
| 129 | extern int pil_boot(struct pil_desc *desc); |
| 130 | extern void pil_shutdown(struct pil_desc *desc); |
| 131 | extern void pil_free_memory(struct pil_desc *desc); |
| 132 | extern void pil_desc_release(struct pil_desc *desc); |
| 133 | extern phys_addr_t pil_get_entry_addr(struct pil_desc *desc); |
| 134 | extern int pil_do_ramdump(struct pil_desc *desc, void *ramdump_dev); |
| 135 | extern int pil_assign_mem_to_subsys(struct pil_desc *desc, phys_addr_t addr, |
| 136 | size_t size); |
| 137 | extern int pil_assign_mem_to_linux(struct pil_desc *desc, phys_addr_t addr, |
| 138 | size_t size); |
| 139 | extern int pil_assign_mem_to_subsys_and_linux(struct pil_desc *desc, |
| 140 | phys_addr_t addr, size_t size); |
| 141 | extern int pil_reclaim_mem(struct pil_desc *desc, phys_addr_t addr, size_t size, |
| 142 | int VMid); |
| 143 | extern bool is_timeout_disabled(void); |
| 144 | #else |
| 145 | static inline int pil_desc_init(struct pil_desc *desc) { return 0; } |
| 146 | static inline int pil_boot(struct pil_desc *desc) { return 0; } |
| 147 | static inline void pil_shutdown(struct pil_desc *desc) { } |
| 148 | static inline void pil_free_memory(struct pil_desc *desc) { } |
| 149 | static inline void pil_desc_release(struct pil_desc *desc) { } |
| 150 | static inline phys_addr_t pil_get_entry_addr(struct pil_desc *desc) |
| 151 | { |
| 152 | return 0; |
| 153 | } |
| 154 | static inline int pil_do_ramdump(struct pil_desc *desc, void *ramdump_dev) |
| 155 | { |
| 156 | return 0; |
| 157 | } |
| 158 | static inline int pil_assign_mem_to_subsys(struct pil_desc *desc, |
| 159 | phys_addr_t addr, size_t size) |
| 160 | { |
| 161 | return 0; |
| 162 | } |
| 163 | static inline int pil_assign_mem_to_linux(struct pil_desc *desc, |
| 164 | phys_addr_t addr, size_t size) |
| 165 | { |
| 166 | return 0; |
| 167 | } |
| 168 | static inline int pil_assign_mem_to_subsys_and_linux(struct pil_desc *desc, |
| 169 | phys_addr_t addr, size_t size) |
| 170 | { |
| 171 | return 0; |
| 172 | } |
| 173 | static inline int pil_reclaim_mem(struct pil_desc *desc, phys_addr_t addr, |
| 174 | size_t size, int VMid) |
| 175 | { |
| 176 | return 0; |
| 177 | } |
| 178 | extern bool is_timeout_disabled(void) { return false; } |
| 179 | #endif |
| 180 | |
| 181 | #endif |