1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2018-2022 Linaro Ltd.
5  */
6 #ifndef _IPA_H_
7 #define _IPA_H_
8 
9 #include <linux/types.h>
10 #include <linux/device.h>
11 #include <linux/notifier.h>
12 #include <linux/pm_wakeup.h>
13 
14 #include "ipa_version.h"
15 #include "gsi.h"
16 #include "ipa_mem.h"
17 #include "ipa_qmi.h"
18 #include "ipa_endpoint.h"
19 #include "ipa_interrupt.h"
20 
21 struct clk;
22 struct icc_path;
23 struct net_device;
24 struct platform_device;
25 
26 struct ipa_power;
27 struct ipa_smp2p;
28 struct ipa_interrupt;
29 
30 /**
31  * struct ipa - IPA information
32  * @gsi:		Embedded GSI structure
33  * @version:		IPA hardware version
34  * @pdev:		Platform device
35  * @completion:		Used to signal pipeline clear transfer complete
36  * @nb:			Notifier block used for remoteproc SSR
37  * @notifier:		Remoteproc SSR notifier
38  * @smp2p:		SMP2P information
39  * @power:		IPA power information
40  * @table_addr:		DMA address of filter/route table content
41  * @table_virt:		Virtual address of filter/route table content
42  * @interrupt:		IPA Interrupt information
43  * @uc_powered:		true if power is active by proxy for microcontroller
44  * @uc_loaded:		true after microcontroller has reported it's ready
45  * @reg_addr:		DMA address used for IPA register access
46  * @reg_virt:		Virtual address used for IPA register access
47  * @regs:		IPA register definitions
48  * @mem_addr:		DMA address of IPA-local memory space
49  * @mem_virt:		Virtual address of IPA-local memory space
50  * @mem_offset:		Offset from @mem_virt used for access to IPA memory
51  * @mem_size:		Total size (bytes) of memory at @mem_virt
52  * @mem_count:		Number of entries in the mem array
53  * @mem:		Array of IPA-local memory region descriptors
54  * @imem_iova:		I/O virtual address of IPA region in IMEM
55  * @imem_size:		Size of IMEM region
56  * @smem_iova:		I/O virtual address of IPA region in SMEM
57  * @smem_size:		Size of SMEM region
58  * @zero_addr:		DMA address of preallocated zero-filled memory
59  * @zero_virt:		Virtual address of preallocated zero-filled memory
60  * @zero_size:		Size (bytes) of preallocated zero-filled memory
61  * @available:		Bit mask indicating endpoints hardware supports
62  * @filter_map:		Bit mask indicating endpoints that support filtering
63  * @initialized:	Bit mask indicating endpoints initialized
64  * @set_up:		Bit mask indicating endpoints set up
65  * @enabled:		Bit mask indicating endpoints enabled
66  * @modem_tx_count:	Number of defined modem TX endoints
67  * @endpoint:		Array of endpoint information
68  * @channel_map:	Mapping of GSI channel to IPA endpoint
69  * @name_map:		Mapping of IPA endpoint name to IPA endpoint
70  * @setup_complete:	Flag indicating whether setup stage has completed
71  * @modem_state:	State of modem (stopped, running)
72  * @modem_netdev:	Network device structure used for modem
73  * @qmi:		QMI information
74  */
75 struct ipa {
76 	struct gsi gsi;
77 	enum ipa_version version;
78 	struct platform_device *pdev;
79 	struct completion completion;
80 	struct notifier_block nb;
81 	void *notifier;
82 	struct ipa_smp2p *smp2p;
83 	struct ipa_power *power;
84 
85 	dma_addr_t table_addr;
86 	__le64 *table_virt;
87 
88 	struct ipa_interrupt *interrupt;
89 	bool uc_powered;
90 	bool uc_loaded;
91 
92 	dma_addr_t reg_addr;
93 	void __iomem *reg_virt;
94 	const struct ipa_regs *regs;
95 
96 	dma_addr_t mem_addr;
97 	void *mem_virt;
98 	u32 mem_offset;
99 	u32 mem_size;
100 	u32 mem_count;
101 	const struct ipa_mem *mem;
102 
103 	unsigned long imem_iova;
104 	size_t imem_size;
105 
106 	unsigned long smem_iova;
107 	size_t smem_size;
108 
109 	dma_addr_t zero_addr;
110 	void *zero_virt;
111 	size_t zero_size;
112 
113 	/* Bit masks indicating endpoint state */
114 	u32 available;		/* supported by hardware */
115 	u32 filter_map;
116 	u32 initialized;
117 	u32 set_up;
118 	u32 enabled;
119 
120 	u32 modem_tx_count;
121 	struct ipa_endpoint endpoint[IPA_ENDPOINT_MAX];
122 	struct ipa_endpoint *channel_map[GSI_CHANNEL_COUNT_MAX];
123 	struct ipa_endpoint *name_map[IPA_ENDPOINT_COUNT];
124 
125 	bool setup_complete;
126 
127 	atomic_t modem_state;		/* enum ipa_modem_state */
128 	struct net_device *modem_netdev;
129 	struct ipa_qmi qmi;
130 };
131 
132 /**
133  * ipa_setup() - Perform IPA setup
134  * @ipa:		IPA pointer
135  *
136  * IPA initialization is broken into stages:  init; config; and setup.
137  * (These have inverses exit, deconfig, and teardown.)
138  *
139  * Activities performed at the init stage can be done without requiring
140  * any access to IPA hardware.  Activities performed at the config stage
141  * require IPA power, because they involve access to IPA registers.
142  * The setup stage is performed only after the GSI hardware is ready
143  * (more on this below).  The setup stage allows the AP to perform
144  * more complex initialization by issuing "immediate commands" using
145  * a special interface to the IPA.
146  *
147  * This function, @ipa_setup(), starts the setup stage.
148  *
149  * In order for the GSI hardware to be functional it needs firmware to be
150  * loaded (in addition to some other low-level initialization).  This early
151  * GSI initialization can be done either by Trust Zone on the AP or by the
152  * modem.
153  *
154  * If it's done by Trust Zone, the AP loads the GSI firmware and supplies
155  * it to Trust Zone to verify and install.  When this completes, if
156  * verification was successful, the GSI layer is ready and ipa_setup()
157  * implements the setup phase of initialization.
158  *
159  * If the modem performs early GSI initialization, the AP needs to know
160  * when this has occurred.  An SMP2P interrupt is used for this purpose,
161  * and receipt of that interrupt triggers the call to ipa_setup().
162  */
163 int ipa_setup(struct ipa *ipa);
164 
165 #endif /* _IPA_H_ */
166