blob: c83b038f9b8cb9d9b9e7ff5f6c09a994ce29cf02 [file] [log] [blame]
Rishabh Bhatnagare9a05bb2018-12-10 11:09:45 -08001/* SPDX-License-Identifier: GPL-2.0-only */
Rishabh Bhatnagar6ff955e2018-05-22 17:57:51 -07002/*
Neeraj Upadhyay9363f062019-09-16 09:59:48 +05303 * Copyright (c) 2010-2019, The Linux Foundation. All rights reserved.
Rishabh Bhatnagar6ff955e2018-05-22 17:57:51 -07004 */
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 Kohli72f4ed32019-06-18 16:53:49 +053011#include <linux/ipc_logging.h>
Rishabh Bhatnagar6ff955e2018-05-22 17:57:51 -070012
13struct device;
14struct module;
15struct pil_priv;
16
Gaurav Kohli72f4ed32019-06-18 16:53:49 +053017extern void *pil_ipc_log;
18
19#define pil_ipc(__msg, ...) \
20do { \
21 if (pil_ipc_log) \
22 ipc_log_string(pil_ipc_log, \
23 "[%s]: "__msg, __func__, ##__VA_ARGS__); \
24} while (0)
Rishabh Bhatnagar6ff955e2018-05-22 17:57:51 -070025/**
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 Samuelov1279fb02019-09-29 07:32:05 +030046 * @extra_size: extra memory allocated at the end of the image.
Rishabh Bhatnagar6ff955e2018-05-22 17:57:51 -070047 */
48struct 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 Sharma2108b2a2018-03-19 14:57:46 +053070 struct md_ss_toc *minidump_ss;
71 struct md_ss_toc **aux_minidump;
Rishabh Bhatnagar6ff955e2018-05-22 17:57:51 -070072 int minidump_id;
Jitendra Sharma2108b2a2018-03-19 14:57:46 +053073 int *aux_minidump_ids;
74 int num_aux_minidump_ids;
Neeraj Upadhyay9363f062019-09-16 09:59:48 +053075 bool minidump_as_elf32;
Amir Samuelov1279fb02019-09-29 07:32:05 +030076 u32 extra_size;
Rishabh Bhatnagar6ff955e2018-05-22 17:57:51 -070077};
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 */
85struct 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 */
103struct 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
117extern int pil_desc_init(struct pil_desc *desc);
118extern int pil_boot(struct pil_desc *desc);
119extern void pil_shutdown(struct pil_desc *desc);
120extern void pil_free_memory(struct pil_desc *desc);
121extern void pil_desc_release(struct pil_desc *desc);
122extern phys_addr_t pil_get_entry_addr(struct pil_desc *desc);
123extern int pil_do_ramdump(struct pil_desc *desc, void *ramdump_dev,
124 void *minidump_dev);
125extern int pil_assign_mem_to_subsys(struct pil_desc *desc, phys_addr_t addr,
126 size_t size);
127extern int pil_assign_mem_to_linux(struct pil_desc *desc, phys_addr_t addr,
128 size_t size);
129extern int pil_assign_mem_to_subsys_and_linux(struct pil_desc *desc,
130 phys_addr_t addr, size_t size);
131extern int pil_reclaim_mem(struct pil_desc *desc, phys_addr_t addr, size_t size,
132 int VMid);
133extern bool is_timeout_disabled(void);
134#else
135static inline int pil_desc_init(struct pil_desc *desc) { return 0; }
136static inline int pil_boot(struct pil_desc *desc) { return 0; }
137static inline void pil_shutdown(struct pil_desc *desc) { }
138static inline void pil_free_memory(struct pil_desc *desc) { }
139static inline void pil_desc_release(struct pil_desc *desc) { }
140static inline phys_addr_t pil_get_entry_addr(struct pil_desc *desc)
141{
142 return 0;
143}
144static inline int pil_do_ramdump(struct pil_desc *desc,
145 void *ramdump_dev, void *minidump_dev)
146{
147 return 0;
148}
149static inline int pil_assign_mem_to_subsys(struct pil_desc *desc,
150 phys_addr_t addr, size_t size)
151{
152 return 0;
153}
154static inline int pil_assign_mem_to_linux(struct pil_desc *desc,
155 phys_addr_t addr, size_t size)
156{
157 return 0;
158}
159static 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}
164static inline int pil_reclaim_mem(struct pil_desc *desc, phys_addr_t addr,
165 size_t size, int VMid)
166{
167 return 0;
168}
169extern bool is_timeout_disabled(void) { return false; }
170#endif
171
172#endif