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