@@ -28,6 +28,13 @@ static struct k_spinlock tlb_lock;
28
28
extern struct k_spinlock sys_mm_drv_common_lock ;
29
29
30
30
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
31
38
32
39
33
40
/* 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
139
146
return 0 ;
140
147
}
141
148
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
+
142
164
int sys_mm_drv_map_page (void * virt , uintptr_t phys , uint32_t flags )
143
165
{
144
166
k_spinlock_key_t key ;
@@ -207,8 +229,12 @@ int sys_mm_drv_map_page(void *virt, uintptr_t phys, uint32_t flags)
207
229
208
230
entry_idx = get_tlb_entry_idx (va );
209
231
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
211
236
237
+ bank_idx = get_hpsram_bank_idx (pa );
212
238
if (!hpsram_ref [bank_idx ]++ ) {
213
239
sys_mm_drv_hpsram_pwr (bank_idx , true, false);
214
240
}
@@ -343,6 +369,11 @@ int sys_mm_drv_unmap_page(void *virt)
343
369
UINT_TO_POINTER (pa ), 1 );
344
370
345
371
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
+
346
377
if (-- hpsram_ref [bank_idx ] == 0 ) {
347
378
sys_mm_drv_hpsram_pwr (bank_idx , false, false);
348
379
}
@@ -615,6 +646,9 @@ static int sys_mm_drv_mm_init(const struct device *dev)
615
646
for (int i = 0 ; i < L2_SRAM_BANK_NUM ; i ++ ) {
616
647
hpsram_ref [i ] = SRAM_BANK_SIZE / CONFIG_MM_DRV_PAGE_SIZE ;
617
648
}
649
+ #ifdef CONFIG_SOC_INTEL_COMM_WIDGET
650
+ used_pages = L2_SRAM_BANK_NUM * SRAM_BANK_SIZE / CONFIG_MM_DRV_PAGE_SIZE ;
651
+ #endif
618
652
619
653
#ifdef CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM
620
654
/*
@@ -641,6 +675,13 @@ static int sys_mm_drv_mm_init(const struct device *dev)
641
675
unused_size );
642
676
#endif
643
677
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
+
644
685
return 0 ;
645
686
}
646
687
0 commit comments