Skip to content

Commit 0e17395

Browse files
softwareckicarlescufi
authored andcommitted
mtl: drv: mm: tlb: Add reporting of memory usage to PMC
The number of HPSRAM memory blocks in use is reported to the PMC via the sideband channel supported by the communication widget. Signed-off-by: Adrian Warecki <[email protected]>
1 parent 8794de2 commit 0e17395

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

drivers/mm/mm_drv_intel_adsp_mtl_tlb.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ static struct k_spinlock tlb_lock;
2828
extern struct k_spinlock sys_mm_drv_common_lock;
2929

3030
static int hpsram_ref[L2_SRAM_BANK_NUM];
31+
#ifdef CONFIG_SOC_INTEL_COMM_WIDGET
32+
#include <adsp_comm_widget.h>
33+
34+
static uint32_t used_pages;
35+
/* PMC uses 32 KB banks */
36+
static uint32_t used_pmc_banks_reported;
37+
#endif
3138

3239

3340
/* Define a marker which is placed by the linker script just after
@@ -139,6 +146,21 @@ static int sys_mm_drv_hpsram_pwr(uint32_t bank_idx, bool enable, bool non_blocki
139146
return 0;
140147
}
141148

149+
#ifdef CONFIG_SOC_INTEL_COMM_WIDGET
150+
static void sys_mm_drv_report_page_usage(void)
151+
{
152+
/* PMC uses 32 KB banks */
153+
uint32_t pmc_banks = ceiling_fraction(used_pages, KB(32) / CONFIG_MM_DRV_PAGE_SIZE);
154+
155+
if (used_pmc_banks_reported != pmc_banks) {
156+
if (!adsp_comm_widget_pmc_send_ipc(pmc_banks)) {
157+
/* Store reported value if message was sent successfully. */
158+
used_pmc_banks_reported = pmc_banks;
159+
}
160+
}
161+
}
162+
#endif
163+
142164
int sys_mm_drv_map_page(void *virt, uintptr_t phys, uint32_t flags)
143165
{
144166
k_spinlock_key_t key;
@@ -207,8 +229,12 @@ int sys_mm_drv_map_page(void *virt, uintptr_t phys, uint32_t flags)
207229

208230
entry_idx = get_tlb_entry_idx(va);
209231

210-
bank_idx = get_hpsram_bank_idx(pa);
232+
#ifdef CONFIG_SOC_INTEL_COMM_WIDGET
233+
used_pages++;
234+
sys_mm_drv_report_page_usage();
235+
#endif
211236

237+
bank_idx = get_hpsram_bank_idx(pa);
212238
if (!hpsram_ref[bank_idx]++) {
213239
sys_mm_drv_hpsram_pwr(bank_idx, true, false);
214240
}
@@ -343,6 +369,11 @@ int sys_mm_drv_unmap_page(void *virt)
343369
UINT_TO_POINTER(pa), 1);
344370

345371
bank_idx = get_hpsram_bank_idx(pa);
372+
#ifdef CONFIG_SOC_INTEL_COMM_WIDGET
373+
used_pages--;
374+
sys_mm_drv_report_page_usage();
375+
#endif
376+
346377
if (--hpsram_ref[bank_idx] == 0) {
347378
sys_mm_drv_hpsram_pwr(bank_idx, false, false);
348379
}
@@ -615,6 +646,9 @@ static int sys_mm_drv_mm_init(const struct device *dev)
615646
for (int i = 0; i < L2_SRAM_BANK_NUM; i++) {
616647
hpsram_ref[i] = SRAM_BANK_SIZE / CONFIG_MM_DRV_PAGE_SIZE;
617648
}
649+
#ifdef CONFIG_SOC_INTEL_COMM_WIDGET
650+
used_pages = L2_SRAM_BANK_NUM * SRAM_BANK_SIZE / CONFIG_MM_DRV_PAGE_SIZE;
651+
#endif
618652

619653
#ifdef CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM
620654
/*
@@ -641,6 +675,13 @@ static int sys_mm_drv_mm_init(const struct device *dev)
641675
unused_size);
642676
#endif
643677

678+
/*
679+
* Notify PMC about used HP-SRAM pages.
680+
*/
681+
#ifdef CONFIG_SOC_INTEL_COMM_WIDGET
682+
sys_mm_drv_report_page_usage();
683+
#endif
684+
644685
return 0;
645686
}
646687

0 commit comments

Comments
 (0)