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_clocked: true if clock is active by proxy for microcontroller 55 * @uc_loaded: true after microcontroller has reported it's ready 56 * @reg_addr: DMA address used for IPA register access 57 * @reg_virt: Virtual address used for IPA register access 58 * @mem_addr: DMA address of IPA-local memory space 59 * @mem_virt: Virtual address of IPA-local memory space 60 * @mem_offset: Offset from @mem_virt used for access to IPA memory 61 * @mem_size: Total size (bytes) of memory at @mem_virt 62 * @mem_count: Number of entries in the mem array 63 * @mem: Array of IPA-local memory region descriptors 64 * @imem_iova: I/O virtual address of IPA region in IMEM 65 * @imem_size: Size of IMEM region 66 * @smem_iova: I/O virtual address of IPA region in SMEM 67 * @smem_size: Size of SMEM region 68 * @zero_addr: DMA address of preallocated zero-filled memory 69 * @zero_virt: Virtual address of preallocated zero-filled memory 70 * @zero_size: Size (bytes) of preallocated zero-filled memory 71 * @available: Bit mask indicating endpoints hardware supports 72 * @filter_map: Bit mask indicating endpoints that support filtering 73 * @initialized: Bit mask indicating endpoints initialized 74 * @set_up: Bit mask indicating endpoints set up 75 * @enabled: Bit mask indicating endpoints enabled 76 * @endpoint: Array of endpoint information 77 * @channel_map: Mapping of GSI channel to IPA endpoint 78 * @name_map: Mapping of IPA endpoint name to IPA endpoint 79 * @setup_complete: Flag indicating whether setup stage has completed 80 * @modem_state: State of modem (stopped, running) 81 * @modem_netdev: Network device structure used for modem 82 * @qmi: QMI information 83 */ 84 struct ipa { 85 struct gsi gsi; 86 DECLARE_BITMAP(flags, IPA_FLAG_COUNT); 87 enum ipa_version version; 88 struct platform_device *pdev; 89 struct completion completion; 90 struct notifier_block nb; 91 void *notifier; 92 struct ipa_smp2p *smp2p; 93 struct ipa_clock *clock; 94 95 dma_addr_t table_addr; 96 __le64 *table_virt; 97 98 struct ipa_interrupt *interrupt; 99 bool uc_clocked; 100 bool uc_loaded; 101 102 dma_addr_t reg_addr; 103 void __iomem *reg_virt; 104 105 dma_addr_t mem_addr; 106 void *mem_virt; 107 u32 mem_offset; 108 u32 mem_size; 109 u32 mem_count; 110 const struct ipa_mem *mem; 111 112 unsigned long imem_iova; 113 size_t imem_size; 114 115 unsigned long smem_iova; 116 size_t smem_size; 117 118 dma_addr_t zero_addr; 119 void *zero_virt; 120 size_t zero_size; 121 122 /* Bit masks indicating endpoint state */ 123 u32 available; /* supported by hardware */ 124 u32 filter_map; 125 u32 initialized; 126 u32 set_up; 127 u32 enabled; 128 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 the IPA clock to be running, because they involve access 150 * to IPA registers. The setup stage is performed only after the GSI 151 * hardware is ready (more on this below). The setup stage allows 152 * the AP to perform more complex initialization by issuing "immediate 153 * commands" using 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 */ 171 int ipa_setup(struct ipa *ipa); 172 173 #endif /* _IPA_H_ */ 174