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