Rishabh Bhatnagar | e9a05bb | 2018-12-10 11:09:45 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Rishabh Bhatnagar | 6ff955e | 2018-05-22 17:57:51 -0700 | [diff] [blame] | 2 | /* |
Neeraj Upadhyay | 9363f06 | 2019-09-16 09:59:48 +0530 | [diff] [blame] | 3 | * Copyright (c) 2010-2019, The Linux Foundation. All rights reserved. |
Rishabh Bhatnagar | 6ff955e | 2018-05-22 17:57:51 -0700 | [diff] [blame] | 4 | */ |
| 5 | #ifndef __MSM_PERIPHERAL_LOADER_H |
| 6 | #define __MSM_PERIPHERAL_LOADER_H |
| 7 | |
| 8 | #include <linux/mailbox_client.h> |
| 9 | #include <linux/mailbox/qmp.h> |
| 10 | #include "minidump_private.h" |
Gaurav Kohli | 72f4ed3 | 2019-06-18 16:53:49 +0530 | [diff] [blame] | 11 | #include <linux/ipc_logging.h> |
Rishabh Bhatnagar | 6ff955e | 2018-05-22 17:57:51 -0700 | [diff] [blame] | 12 | |
| 13 | struct device; |
| 14 | struct module; |
| 15 | struct pil_priv; |
| 16 | |
Gaurav Kohli | 72f4ed3 | 2019-06-18 16:53:49 +0530 | [diff] [blame] | 17 | extern void *pil_ipc_log; |
| 18 | |
| 19 | #define pil_ipc(__msg, ...) \ |
| 20 | do { \ |
| 21 | if (pil_ipc_log) \ |
| 22 | ipc_log_string(pil_ipc_log, \ |
| 23 | "[%s]: "__msg, __func__, ##__VA_ARGS__); \ |
| 24 | } while (0) |
Rishabh Bhatnagar | 6ff955e | 2018-05-22 17:57:51 -0700 | [diff] [blame] | 25 | /** |
| 26 | * struct pil_desc - PIL descriptor |
| 27 | * @name: string used for pil_get() |
| 28 | * @fw_name: firmware name |
| 29 | * @dev: parent device |
| 30 | * @ops: callback functions |
| 31 | * @owner: module the descriptor belongs to |
| 32 | * @proxy_timeout: delay in ms until proxy vote is removed |
| 33 | * @flags: bitfield for image flags |
| 34 | * @priv: DON'T USE - internal only |
| 35 | * @attrs: DMA attributes to be used during dma allocation. |
| 36 | * @proxy_unvote_irq: IRQ to trigger a proxy unvote. proxy_timeout |
| 37 | * is ignored if this is set. |
| 38 | * @map_fw_mem: Custom function used to map physical address space to virtual. |
| 39 | * This defaults to ioremap if not specified. |
| 40 | * @unmap_fw_mem: Custom function used to undo mapping by map_fw_mem. |
| 41 | * This defaults to iounmap if not specified. |
| 42 | * @shutdown_fail: Set if PIL op for shutting down subsystem fails. |
| 43 | * @modem_ssr: true if modem is restarting, false if booting for first time. |
| 44 | * @clear_fw_region: Clear fw region on failure in loading. |
| 45 | * @subsys_vmid: memprot id for the subsystem. |
Amir Samuelov | 1279fb0 | 2019-09-29 07:32:05 +0300 | [diff] [blame] | 46 | * @extra_size: extra memory allocated at the end of the image. |
Rishabh Bhatnagar | 6ff955e | 2018-05-22 17:57:51 -0700 | [diff] [blame] | 47 | */ |
| 48 | struct pil_desc { |
| 49 | const char *name; |
| 50 | const char *fw_name; |
| 51 | struct device *dev; |
| 52 | const struct pil_reset_ops *ops; |
| 53 | struct module *owner; |
| 54 | unsigned long proxy_timeout; |
| 55 | unsigned long flags; |
| 56 | #define PIL_SKIP_ENTRY_CHECK BIT(0) |
| 57 | struct pil_priv *priv; |
| 58 | unsigned long attrs; |
| 59 | unsigned int proxy_unvote_irq; |
| 60 | void * (*map_fw_mem)(phys_addr_t phys, size_t size, void *data); |
| 61 | void (*unmap_fw_mem)(void *virt, size_t size, void *data); |
| 62 | void *map_data; |
| 63 | bool shutdown_fail; |
| 64 | bool modem_ssr; |
| 65 | bool clear_fw_region; |
| 66 | u32 subsys_vmid; |
| 67 | bool signal_aop; |
| 68 | struct mbox_client cl; |
| 69 | struct mbox_chan *mbox; |
Jitendra Sharma | 2108b2a | 2018-03-19 14:57:46 +0530 | [diff] [blame] | 70 | struct md_ss_toc *minidump_ss; |
| 71 | struct md_ss_toc **aux_minidump; |
Rishabh Bhatnagar | 6ff955e | 2018-05-22 17:57:51 -0700 | [diff] [blame] | 72 | int minidump_id; |
Jitendra Sharma | 2108b2a | 2018-03-19 14:57:46 +0530 | [diff] [blame] | 73 | int *aux_minidump_ids; |
| 74 | int num_aux_minidump_ids; |
Neeraj Upadhyay | 9363f06 | 2019-09-16 09:59:48 +0530 | [diff] [blame] | 75 | bool minidump_as_elf32; |
Amir Samuelov | 1279fb0 | 2019-09-29 07:32:05 +0300 | [diff] [blame] | 76 | u32 extra_size; |
Rishabh Bhatnagar | 6ff955e | 2018-05-22 17:57:51 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * struct pil_image_info - info in IMEM about image and where it is loaded |
| 81 | * @name: name of image (may or may not be NULL terminated) |
| 82 | * @start: indicates physical address where image starts (little endian) |
| 83 | * @size: size of image (little endian) |
| 84 | */ |
| 85 | struct pil_image_info { |
| 86 | char name[8]; |
| 87 | __le64 start; |
| 88 | __le32 size; |
| 89 | } __attribute__((__packed__)); |
| 90 | |
| 91 | /** |
| 92 | * struct pil_reset_ops - PIL operations |
| 93 | * @init_image: prepare an image for authentication |
| 94 | * @mem_setup: prepare the image memory region |
| 95 | * @verify_blob: authenticate a program segment, called once for each loadable |
| 96 | * program segment (optional) |
| 97 | * @proxy_vote: make proxy votes before auth_and_reset (optional) |
| 98 | * @auth_and_reset: boot the processor |
| 99 | * @proxy_unvote: remove any proxy votes (optional) |
| 100 | * @deinit_image: restore actions performed in init_image if necessary |
| 101 | * @shutdown: shutdown the processor |
| 102 | */ |
| 103 | struct pil_reset_ops { |
| 104 | int (*init_image)(struct pil_desc *pil, const u8 *metadata, |
| 105 | size_t size); |
| 106 | int (*mem_setup)(struct pil_desc *pil, phys_addr_t addr, size_t size); |
| 107 | int (*verify_blob)(struct pil_desc *pil, phys_addr_t phy_addr, |
| 108 | size_t size); |
| 109 | int (*proxy_vote)(struct pil_desc *pil); |
| 110 | int (*auth_and_reset)(struct pil_desc *pil); |
| 111 | void (*proxy_unvote)(struct pil_desc *pil); |
| 112 | int (*deinit_image)(struct pil_desc *pil); |
| 113 | int (*shutdown)(struct pil_desc *pil); |
| 114 | }; |
| 115 | |
| 116 | #ifdef CONFIG_MSM_PIL |
| 117 | extern int pil_desc_init(struct pil_desc *desc); |
| 118 | extern int pil_boot(struct pil_desc *desc); |
| 119 | extern void pil_shutdown(struct pil_desc *desc); |
| 120 | extern void pil_free_memory(struct pil_desc *desc); |
| 121 | extern void pil_desc_release(struct pil_desc *desc); |
| 122 | extern phys_addr_t pil_get_entry_addr(struct pil_desc *desc); |
| 123 | extern int pil_do_ramdump(struct pil_desc *desc, void *ramdump_dev, |
| 124 | void *minidump_dev); |
| 125 | extern int pil_assign_mem_to_subsys(struct pil_desc *desc, phys_addr_t addr, |
| 126 | size_t size); |
| 127 | extern int pil_assign_mem_to_linux(struct pil_desc *desc, phys_addr_t addr, |
| 128 | size_t size); |
| 129 | extern int pil_assign_mem_to_subsys_and_linux(struct pil_desc *desc, |
| 130 | phys_addr_t addr, size_t size); |
| 131 | extern int pil_reclaim_mem(struct pil_desc *desc, phys_addr_t addr, size_t size, |
| 132 | int VMid); |
| 133 | extern bool is_timeout_disabled(void); |
| 134 | #else |
| 135 | static inline int pil_desc_init(struct pil_desc *desc) { return 0; } |
| 136 | static inline int pil_boot(struct pil_desc *desc) { return 0; } |
| 137 | static inline void pil_shutdown(struct pil_desc *desc) { } |
| 138 | static inline void pil_free_memory(struct pil_desc *desc) { } |
| 139 | static inline void pil_desc_release(struct pil_desc *desc) { } |
| 140 | static inline phys_addr_t pil_get_entry_addr(struct pil_desc *desc) |
| 141 | { |
| 142 | return 0; |
| 143 | } |
| 144 | static inline int pil_do_ramdump(struct pil_desc *desc, |
| 145 | void *ramdump_dev, void *minidump_dev) |
| 146 | { |
| 147 | return 0; |
| 148 | } |
| 149 | static inline int pil_assign_mem_to_subsys(struct pil_desc *desc, |
| 150 | phys_addr_t addr, size_t size) |
| 151 | { |
| 152 | return 0; |
| 153 | } |
| 154 | static inline int pil_assign_mem_to_linux(struct pil_desc *desc, |
| 155 | phys_addr_t addr, size_t size) |
| 156 | { |
| 157 | return 0; |
| 158 | } |
| 159 | static inline int pil_assign_mem_to_subsys_and_linux(struct pil_desc *desc, |
| 160 | phys_addr_t addr, size_t size) |
| 161 | { |
| 162 | return 0; |
| 163 | } |
| 164 | static inline int pil_reclaim_mem(struct pil_desc *desc, phys_addr_t addr, |
| 165 | size_t size, int VMid) |
| 166 | { |
| 167 | return 0; |
| 168 | } |
| 169 | extern bool is_timeout_disabled(void) { return false; } |
| 170 | #endif |
| 171 | |
| 172 | #endif |