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