Loading...
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
21struct clk;
22struct icc_path;
23struct net_device;
24struct platform_device;
25
26struct ipa_power;
27struct ipa_smp2p;
28struct 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 * @route_count: Total number of entries in a routing table
43 * @modem_route_count: Number of modem entries in a routing table
44 * @filter_count: Maximum number of entries in a filter table
45 * @interrupt: IPA Interrupt information
46 * @uc_powered: true if power is active by proxy for microcontroller
47 * @uc_loaded: true after microcontroller has reported it's ready
48 * @reg_virt: Virtual address used for IPA register access
49 * @regs: IPA register definitions
50 * @mem_addr: DMA address of IPA-local memory space
51 * @mem_virt: Virtual address of IPA-local memory space
52 * @mem_offset: Offset from @mem_virt used for access to IPA memory
53 * @mem_size: Total size (bytes) of memory at @mem_virt
54 * @mem_count: Number of entries in the mem array
55 * @mem: Array of IPA-local memory region descriptors
56 * @imem_iova: I/O virtual address of IPA region in IMEM
57 * @imem_size: Size of IMEM region
58 * @smem_iova: I/O virtual address of IPA region in SMEM
59 * @smem_size: Size of SMEM region
60 * @zero_addr: DMA address of preallocated zero-filled memory
61 * @zero_virt: Virtual address of preallocated zero-filled memory
62 * @zero_size: Size (bytes) of preallocated zero-filled memory
63 * @endpoint_count: Number of defined bits in most bitmaps below
64 * @available_count: Number of defined bits in the available bitmap
65 * @defined: Bitmap of endpoints defined in config data
66 * @available: Bitmap of endpoints supported by hardware
67 * @filtered: Bitmap of endpoints that support filtering
68 * @set_up: Bitmap of endpoints that are set up for use
69 * @enabled: Bitmap of currently enabled endpoints
70 * @modem_tx_count: Number of defined modem TX endoints
71 * @endpoint: Array of endpoint information
72 * @channel_map: Mapping of GSI channel to IPA endpoint
73 * @name_map: Mapping of IPA endpoint name to IPA endpoint
74 * @setup_complete: Flag indicating whether setup stage has completed
75 * @modem_state: State of modem (stopped, running)
76 * @modem_netdev: Network device structure used for modem
77 * @qmi: QMI information
78 */
79struct ipa {
80 struct gsi gsi;
81 enum ipa_version version;
82 struct platform_device *pdev;
83 struct completion completion;
84 struct notifier_block nb;
85 void *notifier;
86 struct ipa_smp2p *smp2p;
87 struct ipa_power *power;
88
89 dma_addr_t table_addr;
90 __le64 *table_virt;
91 u32 route_count;
92 u32 modem_route_count;
93 u32 filter_count;
94
95 struct ipa_interrupt *interrupt;
96 bool uc_powered;
97 bool uc_loaded;
98
99 void __iomem *reg_virt;
100 const struct regs *regs;
101
102 dma_addr_t mem_addr;
103 void *mem_virt;
104 u32 mem_offset;
105 u32 mem_size;
106 u32 mem_count;
107 const struct ipa_mem *mem;
108
109 unsigned long imem_iova;
110 size_t imem_size;
111
112 unsigned long smem_iova;
113 size_t smem_size;
114
115 dma_addr_t zero_addr;
116 void *zero_virt;
117 size_t zero_size;
118
119 /* Bitmaps indicating endpoint state */
120 u32 endpoint_count;
121 u32 available_count;
122 unsigned long *defined; /* Defined in configuration data */
123 unsigned long *available; /* Supported by hardware */
124 u64 filtered; /* Support filtering (AP and modem) */
125 unsigned long *set_up;
126 unsigned long *enabled;
127
128 u32 modem_tx_count;
129 struct ipa_endpoint endpoint[IPA_ENDPOINT_MAX];
130 struct ipa_endpoint *channel_map[GSI_CHANNEL_COUNT_MAX];
131 struct ipa_endpoint *name_map[IPA_ENDPOINT_COUNT];
132
133 bool setup_complete;
134
135 atomic_t modem_state; /* enum ipa_modem_state */
136 struct net_device *modem_netdev;
137 struct ipa_qmi qmi;
138};
139
140/**
141 * ipa_setup() - Perform IPA setup
142 * @ipa: IPA pointer
143 *
144 * IPA initialization is broken into stages: init; config; and setup.
145 * (These have inverses exit, deconfig, and teardown.)
146 *
147 * Activities performed at the init stage can be done without requiring
148 * any access to IPA hardware. Activities performed at the config stage
149 * require IPA power, because they involve access to IPA registers.
150 * The setup stage is performed only after the GSI hardware is ready
151 * (more on this below). The setup stage allows the AP to perform
152 * more complex initialization by issuing "immediate commands" using
153 * a special interface to the IPA.
154 *
155 * This function, @ipa_setup(), starts the setup stage.
156 *
157 * In order for the GSI hardware to be functional it needs firmware to be
158 * loaded (in addition to some other low-level initialization). This early
159 * GSI initialization can be done either by Trust Zone on the AP or by the
160 * modem.
161 *
162 * If it's done by Trust Zone, the AP loads the GSI firmware and supplies
163 * it to Trust Zone to verify and install. When this completes, if
164 * verification was successful, the GSI layer is ready and ipa_setup()
165 * implements the setup phase of initialization.
166 *
167 * If the modem performs early GSI initialization, the AP needs to know
168 * when this has occurred. An SMP2P interrupt is used for this purpose,
169 * and receipt of that interrupt triggers the call to ipa_setup().
170 */
171int ipa_setup(struct ipa *ipa);
172
173#endif /* _IPA_H_ */
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
21struct clk;
22struct icc_path;
23struct net_device;
24struct platform_device;
25
26struct ipa_clock;
27struct ipa_smp2p;
28struct 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 */
35enum 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_count: Number of entries in the mem array
62 * @mem: Array of IPA-local memory region descriptors
63 * @imem_iova: I/O virtual address of IPA region in IMEM
64 * @imem_size: Size of IMEM region
65 * @smem_iova: I/O virtual address of IPA region in SMEM
66 * @smem_size: Size of SMEM region
67 * @zero_addr: DMA address of preallocated zero-filled memory
68 * @zero_virt: Virtual address of preallocated zero-filled memory
69 * @zero_size: Size (bytes) of preallocated zero-filled memory
70 * @available: Bit mask indicating endpoints hardware supports
71 * @filter_map: Bit mask indicating endpoints that support filtering
72 * @initialized: Bit mask indicating endpoints initialized
73 * @set_up: Bit mask indicating endpoints set up
74 * @enabled: Bit mask indicating endpoints enabled
75 * @endpoint: Array of endpoint information
76 * @channel_map: Mapping of GSI channel to IPA endpoint
77 * @name_map: Mapping of IPA endpoint name to IPA endpoint
78 * @setup_complete: Flag indicating whether setup stage has completed
79 * @modem_state: State of modem (stopped, running)
80 * @modem_netdev: Network device structure used for modem
81 * @qmi: QMI information
82 */
83struct ipa {
84 struct gsi gsi;
85 DECLARE_BITMAP(flags, IPA_FLAG_COUNT);
86 enum ipa_version version;
87 struct platform_device *pdev;
88 struct completion completion;
89 struct notifier_block nb;
90 void *notifier;
91 struct ipa_smp2p *smp2p;
92 struct ipa_clock *clock;
93
94 dma_addr_t table_addr;
95 __le64 *table_virt;
96
97 struct ipa_interrupt *interrupt;
98 bool uc_loaded;
99
100 dma_addr_t reg_addr;
101 void __iomem *reg_virt;
102
103 dma_addr_t mem_addr;
104 void *mem_virt;
105 u32 mem_offset;
106 u32 mem_size;
107 u32 mem_count;
108 const struct ipa_mem *mem;
109
110 unsigned long imem_iova;
111 size_t imem_size;
112
113 unsigned long smem_iova;
114 size_t smem_size;
115
116 dma_addr_t zero_addr;
117 void *zero_virt;
118 size_t zero_size;
119
120 /* Bit masks indicating endpoint state */
121 u32 available; /* supported by hardware */
122 u32 filter_map;
123 u32 initialized;
124 u32 set_up;
125 u32 enabled;
126
127 struct ipa_endpoint endpoint[IPA_ENDPOINT_MAX];
128 struct ipa_endpoint *channel_map[GSI_CHANNEL_COUNT_MAX];
129 struct ipa_endpoint *name_map[IPA_ENDPOINT_COUNT];
130
131 bool setup_complete;
132
133 atomic_t modem_state; /* enum ipa_modem_state */
134 struct net_device *modem_netdev;
135 struct ipa_qmi qmi;
136};
137
138/**
139 * ipa_setup() - Perform IPA setup
140 * @ipa: IPA pointer
141 *
142 * IPA initialization is broken into stages: init; config; and setup.
143 * (These have inverses exit, deconfig, and teardown.)
144 *
145 * Activities performed at the init stage can be done without requiring
146 * any access to IPA hardware. Activities performed at the config stage
147 * require the IPA clock to be running, because they involve access
148 * to IPA registers. The setup stage is performed only after the GSI
149 * hardware is ready (more on this below). The setup stage allows
150 * the AP to perform more complex initialization by issuing "immediate
151 * commands" using a special interface to the IPA.
152 *
153 * This function, @ipa_setup(), starts the setup stage.
154 *
155 * In order for the GSI hardware to be functional it needs firmware to be
156 * loaded (in addition to some other low-level initialization). This early
157 * GSI initialization can be done either by Trust Zone on the AP or by the
158 * modem.
159 *
160 * If it's done by Trust Zone, the AP loads the GSI firmware and supplies
161 * it to Trust Zone to verify and install. When this completes, if
162 * verification was successful, the GSI layer is ready and ipa_setup()
163 * implements the setup phase of initialization.
164 *
165 * If the modem performs early GSI initialization, the AP needs to know
166 * when this has occurred. An SMP2P interrupt is used for this purpose,
167 * and receipt of that interrupt triggers the call to ipa_setup().
168 */
169int ipa_setup(struct ipa *ipa);
170
171#endif /* _IPA_H_ */