Lines Matching full:ipa
15 #include "ipa.h"
33 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_mem_zero_region_add() local
34 dma_addr_t addr = ipa->zero_addr; in ipa_mem_zero_region_add()
43 * ipa_mem_setup() - Set up IPA AP and modem shared memory areas
44 * @ipa: IPA pointer
46 * Set up the shared memory regions in IPA local memory. This involves
48 * the IPA where it's located.
58 int ipa_mem_setup(struct ipa *ipa) in ipa_mem_setup() argument
60 dma_addr_t addr = ipa->zero_addr; in ipa_mem_setup()
68 trans = ipa_cmd_trans_alloc(ipa, 4); in ipa_mem_setup()
70 dev_err(&ipa->pdev->dev, "no transaction for memory setup\n"); in ipa_mem_setup()
74 /* Initialize IPA-local header memory. The modem and AP header in ipa_mem_setup()
77 offset = ipa->mem[IPA_MEM_MODEM_HEADER].offset; in ipa_mem_setup()
78 size = ipa->mem[IPA_MEM_MODEM_HEADER].size; in ipa_mem_setup()
79 size += ipa->mem[IPA_MEM_AP_HEADER].size; in ipa_mem_setup()
83 ipa_mem_zero_region_add(trans, &ipa->mem[IPA_MEM_MODEM_PROC_CTX]); in ipa_mem_setup()
85 ipa_mem_zero_region_add(trans, &ipa->mem[IPA_MEM_AP_PROC_CTX]); in ipa_mem_setup()
87 ipa_mem_zero_region_add(trans, &ipa->mem[IPA_MEM_MODEM]); in ipa_mem_setup()
92 iowrite32(ipa->mem_offset + offset, in ipa_mem_setup()
93 ipa->reg_virt + IPA_REG_LOCAL_PKT_PROC_CNTXT_BASE_OFFSET); in ipa_mem_setup()
98 void ipa_mem_teardown(struct ipa *ipa) in ipa_mem_teardown() argument
105 static bool ipa_mem_valid(struct ipa *ipa, enum ipa_mem_id mem_id) in ipa_mem_valid() argument
107 const struct ipa_mem *mem = &ipa->mem[mem_id]; in ipa_mem_valid()
108 struct device *dev = &ipa->pdev->dev; in ipa_mem_valid()
121 else if (mem->offset + mem->size > ipa->mem_size) in ipa_mem_valid()
123 mem_id, ipa->mem_size); in ipa_mem_valid()
132 static bool ipa_mem_valid(struct ipa *ipa, enum ipa_mem_id mem_id) in ipa_mem_valid() argument
140 * ipa_mem_config() - Configure IPA shared memory
141 * @ipa: IPA pointer
145 int ipa_mem_config(struct ipa *ipa) in ipa_mem_config() argument
147 struct device *dev = &ipa->pdev->dev; in ipa_mem_config()
155 val = ioread32(ipa->reg_virt + IPA_REG_SHARED_MEM_SIZE_OFFSET); in ipa_mem_config()
158 ipa->mem_offset = 8 * u32_get_bits(val, SHARED_MEM_BADDR_FMASK); in ipa_mem_config()
163 if (ipa->mem_offset + mem_size > ipa->mem_size) { in ipa_mem_config()
166 } else if (ipa->mem_offset + mem_size < ipa->mem_size) { in ipa_mem_config()
167 dev_warn(dev, "limiting IPA memory size to 0x%08x\n", in ipa_mem_config()
169 ipa->mem_size = mem_size; in ipa_mem_config()
176 ipa->zero_addr = addr; in ipa_mem_config()
177 ipa->zero_virt = virt; in ipa_mem_config()
178 ipa->zero_size = IPA_MEM_MAX; in ipa_mem_config()
185 const struct ipa_mem *mem = &ipa->mem[mem_id]; in ipa_mem_config()
190 if (!ipa_mem_valid(ipa, mem_id)) in ipa_mem_config()
202 canary = ipa->mem_virt + ipa->mem_offset + mem->offset; in ipa_mem_config()
209 if (!ipa_table_valid(ipa)) in ipa_mem_config()
213 if (!ipa_cmd_data_valid(ipa)) in ipa_mem_config()
217 if (ipa->mem[IPA_MEM_UC_EVENT_RING].offset % 1024) { in ipa_mem_config()
225 dma_free_coherent(dev, IPA_MEM_MAX, ipa->zero_virt, ipa->zero_addr); in ipa_mem_config()
231 void ipa_mem_deconfig(struct ipa *ipa) in ipa_mem_deconfig() argument
233 struct device *dev = &ipa->pdev->dev; in ipa_mem_deconfig()
235 dma_free_coherent(dev, ipa->zero_size, ipa->zero_virt, ipa->zero_addr); in ipa_mem_deconfig()
236 ipa->zero_size = 0; in ipa_mem_deconfig()
237 ipa->zero_virt = NULL; in ipa_mem_deconfig()
238 ipa->zero_addr = 0; in ipa_mem_deconfig()
242 * ipa_mem_zero_modem() - Zero IPA-local memory regions owned by the modem
243 * @ipa: IPA pointer
245 * Zero regions of IPA-local memory used by the modem. These are configured
248 * modem where to find regions of IPA local memory it needs to know about
251 int ipa_mem_zero_modem(struct ipa *ipa) in ipa_mem_zero_modem() argument
258 trans = ipa_cmd_trans_alloc(ipa, 3); in ipa_mem_zero_modem()
260 dev_err(&ipa->pdev->dev, in ipa_mem_zero_modem()
265 ipa_mem_zero_region_add(trans, &ipa->mem[IPA_MEM_MODEM_HEADER]); in ipa_mem_zero_modem()
267 ipa_mem_zero_region_add(trans, &ipa->mem[IPA_MEM_MODEM_PROC_CTX]); in ipa_mem_zero_modem()
269 ipa_mem_zero_region_add(trans, &ipa->mem[IPA_MEM_MODEM]); in ipa_mem_zero_modem()
277 * ipa_imem_init() - Initialize IMEM memory used by the IPA
278 * @ipa: IPA pointer
279 * @addr: Physical address of the IPA region in IMEM
280 * @size: Size (bytes) of the IPA region in IMEM
283 * a portion of this memory is available for the IPA to use. The
284 * modem accesses this memory directly, but the IPA accesses it
288 * through the IOMMU using the IPA device.
292 static int ipa_imem_init(struct ipa *ipa, unsigned long addr, size_t size) in ipa_imem_init() argument
294 struct device *dev = &ipa->pdev->dev; in ipa_imem_init()
318 ipa->imem_iova = iova; in ipa_imem_init()
319 ipa->imem_size = size; in ipa_imem_init()
324 static void ipa_imem_exit(struct ipa *ipa) in ipa_imem_exit() argument
329 if (!ipa->imem_size) in ipa_imem_exit()
332 dev = &ipa->pdev->dev; in ipa_imem_exit()
337 size = iommu_unmap(domain, ipa->imem_iova, ipa->imem_size); in ipa_imem_exit()
338 if (size != ipa->imem_size) in ipa_imem_exit()
340 size, ipa->imem_size); in ipa_imem_exit()
342 dev_err(dev, "couldn't get IPA IOMMU domain for IMEM\n"); in ipa_imem_exit()
345 ipa->imem_size = 0; in ipa_imem_exit()
346 ipa->imem_iova = 0; in ipa_imem_exit()
350 * ipa_smem_init() - Initialize SMEM memory used by the IPA
351 * @ipa: IPA pointer
356 * can be allocated. One item is designated for use by the IPA.
358 * The modem accesses SMEM memory directly, but the IPA accesses it
366 static int ipa_smem_init(struct ipa *ipa, u32 item, size_t size) in ipa_smem_init() argument
368 struct device *dev = &ipa->pdev->dev; in ipa_smem_init()
426 ipa->smem_iova = iova; in ipa_smem_init()
427 ipa->smem_size = size; in ipa_smem_init()
432 static void ipa_smem_exit(struct ipa *ipa) in ipa_smem_exit() argument
434 struct device *dev = &ipa->pdev->dev; in ipa_smem_exit()
441 size = iommu_unmap(domain, ipa->smem_iova, ipa->smem_size); in ipa_smem_exit()
442 if (size != ipa->smem_size) in ipa_smem_exit()
444 size, ipa->smem_size); in ipa_smem_exit()
447 dev_err(dev, "couldn't get IPA IOMMU domain for SMEM\n"); in ipa_smem_exit()
450 ipa->smem_size = 0; in ipa_smem_exit()
451 ipa->smem_iova = 0; in ipa_smem_exit()
455 int ipa_mem_init(struct ipa *ipa, const struct ipa_mem_data *mem_data) in ipa_mem_init() argument
457 struct device *dev = &ipa->pdev->dev; in ipa_mem_init()
467 ret = dma_set_mask_and_coherent(&ipa->pdev->dev, DMA_BIT_MASK(64)); in ipa_mem_init()
473 res = platform_get_resource_byname(ipa->pdev, IORESOURCE_MEM, in ipa_mem_init()
474 "ipa-shared"); in ipa_mem_init()
477 "DT error getting \"ipa-shared\" memory property\n"); in ipa_mem_init()
481 ipa->mem_virt = memremap(res->start, resource_size(res), MEMREMAP_WC); in ipa_mem_init()
482 if (!ipa->mem_virt) { in ipa_mem_init()
483 dev_err(dev, "unable to remap \"ipa-shared\" memory\n"); in ipa_mem_init()
487 ipa->mem_addr = res->start; in ipa_mem_init()
488 ipa->mem_size = resource_size(res); in ipa_mem_init()
490 /* The ipa->mem[] array is indexed by enum ipa_mem_id values */ in ipa_mem_init()
491 ipa->mem = mem_data->local; in ipa_mem_init()
493 ret = ipa_imem_init(ipa, mem_data->imem_addr, mem_data->imem_size); in ipa_mem_init()
497 ret = ipa_smem_init(ipa, mem_data->smem_id, mem_data->smem_size); in ipa_mem_init()
504 ipa_imem_exit(ipa); in ipa_mem_init()
506 memunmap(ipa->mem_virt); in ipa_mem_init()
512 void ipa_mem_exit(struct ipa *ipa) in ipa_mem_exit() argument
514 ipa_smem_exit(ipa); in ipa_mem_exit()
515 ipa_imem_exit(ipa); in ipa_mem_exit()
516 memunmap(ipa->mem_virt); in ipa_mem_exit()