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