Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 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 | |
Alex Elder | 7aa0e8b | 2021-08-20 11:01:28 -0500 | [diff] [blame] | 26 | struct ipa_power; |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 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 |
Alex Elder | 51c48ce | 2021-01-26 12:57:01 -0600 | [diff] [blame] | 35 | * @completion: Used to signal pipeline clear transfer complete |
Alex Elder | 862d3f2 | 2021-03-28 12:31:05 -0500 | [diff] [blame] | 36 | * @nb: Notifier block used for remoteproc SSR |
| 37 | * @notifier: Remoteproc SSR notifier |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 38 | * @smp2p: SMP2P information |
Alex Elder | 7aa0e8b | 2021-08-20 11:01:28 -0500 | [diff] [blame] | 39 | * @power: IPA power information |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 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 |
Alex Elder | 7aa0e8b | 2021-08-20 11:01:28 -0500 | [diff] [blame] | 43 | * @uc_powered: true if power is active by proxy for microcontroller |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 44 | * @uc_loaded: true after microcontroller has reported it's ready |
| 45 | * @reg_addr: DMA address used for IPA register access |
| 46 | * @reg_virt: Virtual address used for IPA register access |
| 47 | * @mem_addr: DMA address of IPA-local memory space |
| 48 | * @mem_virt: Virtual address of IPA-local memory space |
| 49 | * @mem_offset: Offset from @mem_virt used for access to IPA memory |
| 50 | * @mem_size: Total size (bytes) of memory at @mem_virt |
Alex Elder | 440c324 | 2021-05-11 14:42:04 -0500 | [diff] [blame] | 51 | * @mem_count: Number of entries in the mem array |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 52 | * @mem: Array of IPA-local memory region descriptors |
Alex Elder | 3e313c3 | 2020-05-04 12:58:58 -0500 | [diff] [blame] | 53 | * @imem_iova: I/O virtual address of IPA region in IMEM |
Alex Elder | 862d3f2 | 2021-03-28 12:31:05 -0500 | [diff] [blame] | 54 | * @imem_size: Size of IMEM region |
Alex Elder | a0036bb | 2020-05-04 12:58:59 -0500 | [diff] [blame] | 55 | * @smem_iova: I/O virtual address of IPA region in SMEM |
Alex Elder | 862d3f2 | 2021-03-28 12:31:05 -0500 | [diff] [blame] | 56 | * @smem_size: Size of SMEM region |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 57 | * @zero_addr: DMA address of preallocated zero-filled memory |
| 58 | * @zero_virt: Virtual address of preallocated zero-filled memory |
| 59 | * @zero_size: Size (bytes) of preallocated zero-filled memory |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 60 | * @available: Bit mask indicating endpoints hardware supports |
| 61 | * @filter_map: Bit mask indicating endpoints that support filtering |
| 62 | * @initialized: Bit mask indicating endpoints initialized |
| 63 | * @set_up: Bit mask indicating endpoints set up |
| 64 | * @enabled: Bit mask indicating endpoints enabled |
| 65 | * @endpoint: Array of endpoint information |
| 66 | * @channel_map: Mapping of GSI channel to IPA endpoint |
| 67 | * @name_map: Mapping of IPA endpoint name to IPA endpoint |
| 68 | * @setup_complete: Flag indicating whether setup stage has completed |
| 69 | * @modem_state: State of modem (stopped, running) |
| 70 | * @modem_netdev: Network device structure used for modem |
| 71 | * @qmi: QMI information |
| 72 | */ |
| 73 | struct ipa { |
| 74 | struct gsi gsi; |
| 75 | enum ipa_version version; |
| 76 | struct platform_device *pdev; |
Alex Elder | 51c48ce | 2021-01-26 12:57:01 -0600 | [diff] [blame] | 77 | struct completion completion; |
Alex Elder | 30eb3fb | 2020-07-24 13:11:41 -0500 | [diff] [blame] | 78 | struct notifier_block nb; |
| 79 | void *notifier; |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 80 | struct ipa_smp2p *smp2p; |
Alex Elder | 7aa0e8b | 2021-08-20 11:01:28 -0500 | [diff] [blame] | 81 | struct ipa_power *power; |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 82 | |
| 83 | dma_addr_t table_addr; |
| 84 | __le64 *table_virt; |
| 85 | |
| 86 | struct ipa_interrupt *interrupt; |
Alex Elder | 7aa0e8b | 2021-08-20 11:01:28 -0500 | [diff] [blame] | 87 | bool uc_powered; |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 88 | bool uc_loaded; |
| 89 | |
| 90 | dma_addr_t reg_addr; |
| 91 | void __iomem *reg_virt; |
| 92 | |
| 93 | dma_addr_t mem_addr; |
| 94 | void *mem_virt; |
| 95 | u32 mem_offset; |
| 96 | u32 mem_size; |
Alex Elder | 440c324 | 2021-05-11 14:42:04 -0500 | [diff] [blame] | 97 | u32 mem_count; |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 98 | const struct ipa_mem *mem; |
| 99 | |
Alex Elder | 3e313c3 | 2020-05-04 12:58:58 -0500 | [diff] [blame] | 100 | unsigned long imem_iova; |
| 101 | size_t imem_size; |
| 102 | |
Alex Elder | a0036bb | 2020-05-04 12:58:59 -0500 | [diff] [blame] | 103 | unsigned long smem_iova; |
| 104 | size_t smem_size; |
| 105 | |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 106 | dma_addr_t zero_addr; |
| 107 | void *zero_virt; |
| 108 | size_t zero_size; |
| 109 | |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 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 |
Alex Elder | 7aa0e8b | 2021-08-20 11:01:28 -0500 | [diff] [blame] | 137 | * require IPA power, because they involve access to IPA registers. |
| 138 | * The setup stage is performed only after the GSI hardware is ready |
| 139 | * (more on this below). The setup stage allows the AP to perform |
| 140 | * more complex initialization by issuing "immediate commands" using |
| 141 | * a special interface to the IPA. |
Alex Elder | cdf2e94 | 2020-03-05 22:28:17 -0600 | [diff] [blame] | 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_ */ |