^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2019-2020 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef _IPA_MEM_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define _IPA_MEM_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) struct ipa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) struct ipa_mem_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * DOC: IPA Local Memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * The IPA has a block of shared memory, divided into regions used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * specific purposes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * The regions within the shared block are bounded by an offset (relative to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * the "ipa-shared" memory range) and size found in the IPA_SHARED_MEM_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Each region is optionally preceded by one or more 32-bit "canary" values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * These are meant to detect out-of-range writes (if they become corrupted).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * A given region (such as a filter or routing table) has the same number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * of canaries for all IPA hardware versions. Still, the number used is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * defined in the config data, allowing for generic handling of regions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * The set of memory regions is defined in configuration data. They are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * subject to these constraints:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * - a zero offset and zero size represents and undefined region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * - a region's offset is defined to be *past* all "canary" values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * - offset must be large enough to account for all canaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * - a region's size may be zero, but may still have canaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * - all offsets must be 8-byte aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * - most sizes must be a multiple of 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * - modem memory size must be a multiple of 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * - the microcontroller ring offset must be a multiple of 1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* The maximum allowed size for any memory region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define IPA_MEM_MAX (2 * PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* IPA-resident memory region ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) enum ipa_mem_id {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) IPA_MEM_UC_SHARED, /* 0 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) IPA_MEM_UC_INFO, /* 0 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) IPA_MEM_V4_FILTER_HASHED, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) IPA_MEM_V4_FILTER, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) IPA_MEM_V6_FILTER_HASHED, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) IPA_MEM_V6_FILTER, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) IPA_MEM_V4_ROUTE_HASHED, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) IPA_MEM_V4_ROUTE, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) IPA_MEM_V6_ROUTE_HASHED, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) IPA_MEM_V6_ROUTE, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) IPA_MEM_MODEM_HEADER, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) IPA_MEM_AP_HEADER, /* 0 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) IPA_MEM_MODEM_PROC_CTX, /* 2 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) IPA_MEM_AP_PROC_CTX, /* 0 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) IPA_MEM_PDN_CONFIG, /* 2 canaries (IPA v4.0 and above) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) IPA_MEM_STATS_QUOTA, /* 2 canaries (IPA v4.0 and above) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) IPA_MEM_STATS_TETHERING, /* 0 canaries (IPA v4.0 and above) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) IPA_MEM_STATS_DROP, /* 0 canaries (IPA v4.0 and above) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) IPA_MEM_MODEM, /* 0 canaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) IPA_MEM_UC_EVENT_RING, /* 1 canary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) IPA_MEM_COUNT, /* Number of regions (not an index) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * struct ipa_mem - IPA local memory region description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * @offset: offset in IPA memory space to base of the region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @size: size in bytes base of the region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * @canary_count # 32-bit "canary" values that precede region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct ipa_mem {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u16 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u16 canary_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int ipa_mem_config(struct ipa *ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) void ipa_mem_deconfig(struct ipa *ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int ipa_mem_setup(struct ipa *ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void ipa_mem_teardown(struct ipa *ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int ipa_mem_zero_modem(struct ipa *ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int ipa_mem_init(struct ipa *ipa, const struct ipa_mem_data *mem_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) void ipa_mem_exit(struct ipa *ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #endif /* _IPA_MEM_H_ */