Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1 | /* Copyright (c) 2016, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef IPA_MHI_H_ |
| 14 | #define IPA_MHI_H_ |
| 15 | |
| 16 | #include <linux/ipa.h> |
| 17 | #include <linux/types.h> |
| 18 | |
| 19 | /** |
| 20 | * enum ipa_mhi_event_type - event type for mhi callback |
| 21 | * |
| 22 | * @IPA_MHI_EVENT_READY: IPA MHI is ready and IPA uC is loaded. After getting |
| 23 | * this event MHI client is expected to call to ipa_mhi_start() API |
| 24 | * @IPA_MHI_EVENT_DATA_AVAILABLE: downlink data available on MHI channel |
| 25 | */ |
| 26 | enum ipa_mhi_event_type { |
| 27 | IPA_MHI_EVENT_READY, |
| 28 | IPA_MHI_EVENT_DATA_AVAILABLE, |
| 29 | IPA_MHI_EVENT_MAX, |
| 30 | }; |
| 31 | |
| 32 | typedef void (*mhi_client_cb)(void *priv, enum ipa_mhi_event_type event, |
| 33 | unsigned long data); |
| 34 | |
| 35 | /** |
| 36 | * struct ipa_mhi_msi_info - parameters for MSI (Message Signaled Interrupts) |
| 37 | * @addr_low: MSI lower base physical address |
| 38 | * @addr_hi: MSI higher base physical address |
| 39 | * @data: Data Pattern to use when generating the MSI |
| 40 | * @mask: Mask indicating number of messages assigned by the host to device |
| 41 | * |
| 42 | * msi value is written according to this formula: |
| 43 | * ((data & ~mask) | (mmio.msiVec & mask)) |
| 44 | */ |
| 45 | struct ipa_mhi_msi_info { |
| 46 | u32 addr_low; |
| 47 | u32 addr_hi; |
| 48 | u32 data; |
| 49 | u32 mask; |
| 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * struct ipa_mhi_init_params - parameters for IPA MHI initialization API |
| 54 | * |
| 55 | * @msi: MSI (Message Signaled Interrupts) parameters |
| 56 | * @mmio_addr: MHI MMIO physical address |
| 57 | * @first_ch_idx: First channel ID for hardware accelerated channels. |
| 58 | * @first_er_idx: First event ring ID for hardware accelerated channels. |
| 59 | * @assert_bit40: should assert bit 40 in order to access host space. |
| 60 | * if PCIe iATU is configured then not need to assert bit40 |
| 61 | * @notify: client callback |
| 62 | * @priv: client private data to be provided in client callback |
| 63 | * @test_mode: flag to indicate if IPA MHI is in unit test mode |
| 64 | */ |
| 65 | struct ipa_mhi_init_params { |
| 66 | struct ipa_mhi_msi_info msi; |
| 67 | u32 mmio_addr; |
| 68 | u32 first_ch_idx; |
| 69 | u32 first_er_idx; |
| 70 | bool assert_bit40; |
| 71 | mhi_client_cb notify; |
| 72 | void *priv; |
| 73 | bool test_mode; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * struct ipa_mhi_start_params - parameters for IPA MHI start API |
| 78 | * |
| 79 | * @host_ctrl_addr: Base address of MHI control data structures |
| 80 | * @host_data_addr: Base address of MHI data buffers |
| 81 | * @channel_context_addr: channel context array address in host address space |
| 82 | * @event_context_addr: event context array address in host address space |
| 83 | */ |
| 84 | struct ipa_mhi_start_params { |
| 85 | u32 host_ctrl_addr; |
| 86 | u32 host_data_addr; |
| 87 | u64 channel_context_array_addr; |
| 88 | u64 event_context_array_addr; |
| 89 | }; |
| 90 | |
| 91 | /** |
| 92 | * struct ipa_mhi_connect_params - parameters for IPA MHI channel connect API |
| 93 | * |
| 94 | * @sys: IPA EP configuration info |
| 95 | * @channel_id: MHI channel id |
| 96 | */ |
| 97 | struct ipa_mhi_connect_params { |
| 98 | struct ipa_sys_connect_params sys; |
| 99 | u8 channel_id; |
| 100 | }; |
| 101 | |
| 102 | /* bit #40 in address should be asserted for MHI transfers over pcie */ |
| 103 | #define IPA_MHI_HOST_ADDR(addr) ((addr) | BIT_ULL(40)) |
| 104 | |
| 105 | #if defined CONFIG_IPA || defined CONFIG_IPA3 |
| 106 | |
| 107 | int ipa_mhi_init(struct ipa_mhi_init_params *params); |
| 108 | |
| 109 | int ipa_mhi_start(struct ipa_mhi_start_params *params); |
| 110 | |
| 111 | int ipa_mhi_connect_pipe(struct ipa_mhi_connect_params *in, u32 *clnt_hdl); |
| 112 | |
| 113 | int ipa_mhi_disconnect_pipe(u32 clnt_hdl); |
| 114 | |
| 115 | int ipa_mhi_suspend(bool force); |
| 116 | |
| 117 | int ipa_mhi_resume(void); |
| 118 | |
| 119 | void ipa_mhi_destroy(void); |
| 120 | |
| 121 | #else /* (CONFIG_IPA || CONFIG_IPA3) */ |
| 122 | |
| 123 | static inline int ipa_mhi_init(struct ipa_mhi_init_params *params) |
| 124 | { |
| 125 | return -EPERM; |
| 126 | } |
| 127 | |
| 128 | static inline int ipa_mhi_start(struct ipa_mhi_start_params *params) |
| 129 | { |
| 130 | return -EPERM; |
| 131 | } |
| 132 | |
| 133 | static inline int ipa_mhi_connect_pipe(struct ipa_mhi_connect_params *in, |
| 134 | u32 *clnt_hdl) |
| 135 | { |
| 136 | return -EPERM; |
| 137 | } |
| 138 | |
| 139 | static inline int ipa_mhi_disconnect_pipe(u32 clnt_hdl) |
| 140 | { |
| 141 | return -EPERM; |
| 142 | } |
| 143 | |
| 144 | static inline int ipa_mhi_suspend(bool force) |
| 145 | { |
| 146 | return -EPERM; |
| 147 | } |
| 148 | |
| 149 | static inline int ipa_mhi_resume(void) |
| 150 | { |
| 151 | return -EPERM; |
| 152 | } |
| 153 | |
| 154 | static inline void ipa_mhi_destroy(void) |
| 155 | { |
| 156 | |
| 157 | } |
| 158 | |
| 159 | #endif /* (CONFIG_IPA || CONFIG_IPA3) */ |
| 160 | |
| 161 | #endif /* IPA_MHI_H_ */ |