Lines Matching full:ipa

16 #include "ipa.h"
29 const struct ipa_mem *ipa_mem_find(struct ipa *ipa, enum ipa_mem_id mem_id) in ipa_mem_find() argument
33 for (i = 0; i < ipa->mem_count; i++) { in ipa_mem_find()
34 const struct ipa_mem *mem = &ipa->mem[i]; in ipa_mem_find()
47 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_mem_zero_region_add() local
48 const struct ipa_mem *mem = ipa_mem_find(ipa, mem_id); in ipa_mem_zero_region_add()
49 dma_addr_t addr = ipa->zero_addr; in ipa_mem_zero_region_add()
58 * ipa_mem_setup() - Set up IPA AP and modem shared memory areas
59 * @ipa: IPA pointer
61 * Set up the shared memory regions in IPA local memory. This involves
63 * the IPA where it's located.
75 int ipa_mem_setup(struct ipa *ipa) in ipa_mem_setup() argument
77 dma_addr_t addr = ipa->zero_addr; in ipa_mem_setup()
88 trans = ipa_cmd_trans_alloc(ipa, 4); in ipa_mem_setup()
90 dev_err(ipa->dev, "no transaction for memory setup\n"); in ipa_mem_setup()
94 /* Initialize IPA-local header memory. The AP header region, if in ipa_mem_setup()
98 mem = ipa_mem_find(ipa, IPA_MEM_MODEM_HEADER); in ipa_mem_setup()
101 mem = ipa_mem_find(ipa, IPA_MEM_AP_HEADER); in ipa_mem_setup()
114 mem = ipa_mem_find(ipa, IPA_MEM_MODEM_PROC_CTX); in ipa_mem_setup()
115 offset = ipa->mem_offset + mem->offset; in ipa_mem_setup()
117 reg = ipa_reg(ipa, LOCAL_PKT_PROC_CNTXT); in ipa_mem_setup()
119 iowrite32(val, ipa->reg_virt + reg_offset(reg)); in ipa_mem_setup()
124 /* Is the given memory region ID is valid for the current IPA version? */
125 static bool ipa_mem_id_valid(struct ipa *ipa, enum ipa_mem_id mem_id) in ipa_mem_id_valid() argument
127 enum ipa_version version = ipa->version; in ipa_mem_id_valid()
186 static bool ipa_mem_id_required(struct ipa *ipa, enum ipa_mem_id mem_id) in ipa_mem_id_required() argument
207 return ipa->version >= IPA_VERSION_4_0; in ipa_mem_id_required()
210 return ipa->version >= IPA_VERSION_4_0 && in ipa_mem_id_required()
211 ipa->version != IPA_VERSION_5_0; in ipa_mem_id_required()
218 static bool ipa_mem_valid_one(struct ipa *ipa, const struct ipa_mem *mem) in ipa_mem_valid_one() argument
221 struct device *dev = ipa->dev; in ipa_mem_valid_one()
224 /* Make sure the memory region is valid for this version of IPA */ in ipa_mem_valid_one()
225 if (!ipa_mem_id_valid(ipa, mem_id)) { in ipa_mem_valid_one()
254 static bool ipa_mem_valid(struct ipa *ipa, const struct ipa_mem_data *mem_data) in ipa_mem_valid() argument
257 struct device *dev = ipa->dev; in ipa_mem_valid()
276 if (!ipa_mem_valid_one(ipa, mem)) in ipa_mem_valid()
282 if (ipa_mem_id_required(ipa, mem_id)) in ipa_mem_valid()
290 /* Do all memory regions fit within the IPA local memory? */
291 static bool ipa_mem_size_valid(struct ipa *ipa) in ipa_mem_size_valid() argument
293 struct device *dev = ipa->dev; in ipa_mem_size_valid()
294 u32 limit = ipa->mem_size; in ipa_mem_size_valid()
297 for (i = 0; i < ipa->mem_count; i++) { in ipa_mem_size_valid()
298 const struct ipa_mem *mem = &ipa->mem[i]; in ipa_mem_size_valid()
313 * ipa_mem_config() - Configure IPA shared memory
314 * @ipa: IPA pointer
318 int ipa_mem_config(struct ipa *ipa) in ipa_mem_config() argument
320 struct device *dev = ipa->dev; in ipa_mem_config()
330 reg = ipa_reg(ipa, SHARED_MEM_SIZE); in ipa_mem_config()
331 val = ioread32(ipa->reg_virt + reg_offset(reg)); in ipa_mem_config()
334 ipa->mem_offset = 8 * reg_decode(reg, MEM_BADDR, val); in ipa_mem_config()
340 if (ipa->mem_offset + mem_size < ipa->mem_size) { in ipa_mem_config()
341 dev_warn(dev, "limiting IPA memory size to 0x%08x\n", in ipa_mem_config()
343 ipa->mem_size = mem_size; in ipa_mem_config()
344 } else if (ipa->mem_offset + mem_size > ipa->mem_size) { in ipa_mem_config()
350 if (!ipa_mem_size_valid(ipa)) in ipa_mem_config()
357 ipa->zero_addr = addr; in ipa_mem_config()
358 ipa->zero_virt = virt; in ipa_mem_config()
359 ipa->zero_size = IPA_MEM_MAX; in ipa_mem_config()
364 for (i = 0; i < ipa->mem_count; i++) { in ipa_mem_config()
365 u16 canary_count = ipa->mem[i].canary_count; in ipa_mem_config()
372 canary = ipa->mem_virt + ipa->mem_offset + ipa->mem[i].offset; in ipa_mem_config()
379 mem = ipa_mem_find(ipa, IPA_MEM_UC_EVENT_RING); in ipa_mem_config()
388 dma_free_coherent(dev, IPA_MEM_MAX, ipa->zero_virt, ipa->zero_addr); in ipa_mem_config()
394 void ipa_mem_deconfig(struct ipa *ipa) in ipa_mem_deconfig() argument
396 struct device *dev = ipa->dev; in ipa_mem_deconfig()
398 dma_free_coherent(dev, ipa->zero_size, ipa->zero_virt, ipa->zero_addr); in ipa_mem_deconfig()
399 ipa->zero_size = 0; in ipa_mem_deconfig()
400 ipa->zero_virt = NULL; in ipa_mem_deconfig()
401 ipa->zero_addr = 0; in ipa_mem_deconfig()
405 * ipa_mem_zero_modem() - Zero IPA-local memory regions owned by the modem
406 * @ipa: IPA pointer
408 * Zero regions of IPA-local memory used by the modem. These are configured
411 * modem where to find regions of IPA local memory it needs to know about
414 int ipa_mem_zero_modem(struct ipa *ipa) in ipa_mem_zero_modem() argument
421 trans = ipa_cmd_trans_alloc(ipa, 3); in ipa_mem_zero_modem()
423 dev_err(ipa->dev, "no transaction to zero modem memory\n"); in ipa_mem_zero_modem()
437 * ipa_imem_init() - Initialize IMEM memory used by the IPA
438 * @ipa: IPA pointer
439 * @addr: Physical address of the IPA region in IMEM
440 * @size: Size (bytes) of the IPA region in IMEM
443 * a portion of this memory is available for the IPA to use. The
444 * modem accesses this memory directly, but the IPA accesses it
448 * through the IOMMU using the IPA device.
452 static int ipa_imem_init(struct ipa *ipa, unsigned long addr, size_t size) in ipa_imem_init() argument
454 struct device *dev = ipa->dev; in ipa_imem_init()
479 ipa->imem_iova = iova; in ipa_imem_init()
480 ipa->imem_size = size; in ipa_imem_init()
485 static void ipa_imem_exit(struct ipa *ipa) in ipa_imem_exit() argument
487 struct device *dev = ipa->dev; in ipa_imem_exit()
490 if (!ipa->imem_size) in ipa_imem_exit()
497 size = iommu_unmap(domain, ipa->imem_iova, ipa->imem_size); in ipa_imem_exit()
498 if (size != ipa->imem_size) in ipa_imem_exit()
500 size, ipa->imem_size); in ipa_imem_exit()
502 dev_err(dev, "couldn't get IPA IOMMU domain for IMEM\n"); in ipa_imem_exit()
505 ipa->imem_size = 0; in ipa_imem_exit()
506 ipa->imem_iova = 0; in ipa_imem_exit()
510 * ipa_smem_init() - Initialize SMEM memory used by the IPA
511 * @ipa: IPA pointer
516 * can be allocated. One item is designated for use by the IPA.
518 * The modem accesses SMEM memory directly, but the IPA accesses it
526 static int ipa_smem_init(struct ipa *ipa, u32 item, size_t size) in ipa_smem_init() argument
528 struct device *dev = ipa->dev; in ipa_smem_init()
587 ipa->smem_iova = iova; in ipa_smem_init()
588 ipa->smem_size = size; in ipa_smem_init()
593 static void ipa_smem_exit(struct ipa *ipa) in ipa_smem_exit() argument
595 struct device *dev = ipa->dev; in ipa_smem_exit()
602 size = iommu_unmap(domain, ipa->smem_iova, ipa->smem_size); in ipa_smem_exit()
603 if (size != ipa->smem_size) in ipa_smem_exit()
605 size, ipa->smem_size); in ipa_smem_exit()
608 dev_err(dev, "couldn't get IPA IOMMU domain for SMEM\n"); in ipa_smem_exit()
611 ipa->smem_size = 0; in ipa_smem_exit()
612 ipa->smem_iova = 0; in ipa_smem_exit()
616 int ipa_mem_init(struct ipa *ipa, struct platform_device *pdev, in ipa_mem_init() argument
624 if (!ipa_mem_valid(ipa, mem_data)) in ipa_mem_init()
627 ipa->mem_count = mem_data->local_count; in ipa_mem_init()
628 ipa->mem = mem_data->local; in ipa_mem_init()
631 if (!ipa_table_mem_valid(ipa, false)) in ipa_mem_init()
633 if (!ipa_table_mem_valid(ipa, true)) in ipa_mem_init()
642 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ipa-shared"); in ipa_mem_init()
645 "DT error getting \"ipa-shared\" memory property\n"); in ipa_mem_init()
649 ipa->mem_virt = memremap(res->start, resource_size(res), MEMREMAP_WC); in ipa_mem_init()
650 if (!ipa->mem_virt) { in ipa_mem_init()
651 dev_err(dev, "unable to remap \"ipa-shared\" memory\n"); in ipa_mem_init()
655 ipa->mem_addr = res->start; in ipa_mem_init()
656 ipa->mem_size = resource_size(res); in ipa_mem_init()
658 ret = ipa_imem_init(ipa, mem_data->imem_addr, mem_data->imem_size); in ipa_mem_init()
662 ret = ipa_smem_init(ipa, mem_data->smem_id, mem_data->smem_size); in ipa_mem_init()
669 ipa_imem_exit(ipa); in ipa_mem_init()
671 memunmap(ipa->mem_virt); in ipa_mem_init()
677 void ipa_mem_exit(struct ipa *ipa) in ipa_mem_exit() argument
679 ipa_smem_exit(ipa); in ipa_mem_exit()
680 ipa_imem_exit(ipa); in ipa_mem_exit()
681 memunmap(ipa->mem_virt); in ipa_mem_exit()