hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/firmware/rockchip_sip.c
....@@ -262,6 +262,7 @@
262262
263263 return res;
264264 }
265
+EXPORT_SYMBOL_GPL(sip_smc_lastlog_request);
265266
266267 int sip_smc_amp_config(u32 sub_func_id, u32 arg1, u32 arg2, u32 arg3)
267268 {
....@@ -271,6 +272,7 @@
271272 0, 0, 0, &res);
272273 return res.a0;
273274 }
275
+EXPORT_SYMBOL_GPL(sip_smc_amp_config);
274276
275277 struct arm_smccc_res sip_smc_get_amp_info(u32 sub_func_id, u32 arg1)
276278 {
....@@ -279,8 +281,38 @@
279281 arm_smccc_smc(RK_SIP_AMP_CFG, sub_func_id, arg1, 0, 0, 0, 0, 0, &res);
280282 return res;
281283 }
284
+EXPORT_SYMBOL_GPL(sip_smc_get_amp_info);
282285
283
-EXPORT_SYMBOL_GPL(sip_smc_lastlog_request);
286
+void __iomem *sip_hdcp_request_share_memory(int id)
287
+{
288
+ static void __iomem *base;
289
+ struct arm_smccc_res res;
290
+
291
+ if (id < 0 || id >= MAX_DEVICE) {
292
+ pr_err("%s: invalid device id\n", __func__);
293
+ return NULL;
294
+ }
295
+
296
+ if (!base) {
297
+ /* request page share memory */
298
+ res = sip_smc_request_share_mem(2, SHARE_PAGE_TYPE_HDCP);
299
+ if (IS_SIP_ERROR(res.a0))
300
+ return NULL;
301
+ base = (void __iomem *)res.a1;
302
+ }
303
+
304
+ return base + id * 1024;
305
+}
306
+EXPORT_SYMBOL_GPL(sip_hdcp_request_share_memory);
307
+
308
+struct arm_smccc_res sip_hdcp_config(u32 arg0, u32 arg1, u32 arg2)
309
+{
310
+ struct arm_smccc_res res;
311
+
312
+ res = __invoke_sip_fn_smc(SIP_HDCP_CONFIG, arg0, arg1, arg2);
313
+ return res;
314
+}
315
+EXPORT_SYMBOL_GPL(sip_hdcp_config);
284316
285317 /************************** fiq debugger **************************************/
286318 /*
....@@ -291,17 +323,13 @@
291323 */
292324 #ifdef CONFIG_ARM64
293325 #define SIP_UARTDBG_FN SIP_UARTDBG_CFG64
294
-#define SIP_FIQ_DBG_STACK_SIZE IRQ_STACK_SIZE
295326 #else
296327 #define SIP_UARTDBG_FN SIP_UARTDBG_CFG
297
-#define SIP_FIQ_DBG_STACK_SIZE SZ_8K
298
-
299328 static int firmware_64_32bit;
300329 #endif
301330
302331 static int fiq_sip_enabled;
303332 static int fiq_target_cpu;
304
-static unsigned long fiq_stack_top;
305333 static phys_addr_t ft_fiq_mem_phy;
306334 static void __iomem *ft_fiq_mem_base;
307335 static sip_fiq_debugger_uart_irq_tf_cb_t sip_fiq_debugger_uart_irq_tf;
....@@ -410,26 +438,13 @@
410438 {
411439 struct arm_smccc_res res;
412440
413
- /* Alloc a page for fiq_debugger's stack */
414
- if (fiq_stack_top == 0) {
415
- fiq_stack_top = __get_free_pages(GFP_KERNEL | __GFP_ZERO,
416
- get_order(SIP_FIQ_DBG_STACK_SIZE));
417
- if (fiq_stack_top) {
418
- fiq_stack_top += SIP_FIQ_DBG_STACK_SIZE;
419
- } else {
420
- pr_err("%s: alloc stack failed\n", __func__);
421
- return -ENOMEM;
422
- }
423
- }
441
+ fiq_target_cpu = 0;
424442
425443 /* init fiq debugger callback */
426444 sip_fiq_debugger_uart_irq_tf = callback_fn;
427
- arm_smccc_smc(SIP_UARTDBG_FN,
428
- irq_id,
429
- (unsigned long)sip_fiq_debugger_uart_irq_tf_cb,
430
- UARTDBG_CFG_INIT,
431
- fiq_stack_top, 0, 0, 0, &res);
432
-
445
+ res = __invoke_sip_fn_smc(SIP_UARTDBG_FN, irq_id,
446
+ (unsigned long)sip_fiq_debugger_uart_irq_tf_cb,
447
+ UARTDBG_CFG_INIT);
433448 if (IS_SIP_ERROR(res.a0)) {
434449 pr_err("%s error: %d\n", __func__, (int)res.a0);
435450 return res.a0;
....@@ -456,22 +471,33 @@
456471 {
457472 #ifdef MODULE
458473 /* Empirically, local "cpu_logical_map()" for rockchip platforms */
459
- ulong mpidr = 0x00;
474
+ ulong mpidr = read_cpuid_mpidr();
460475
461
- if (cpu < 4)
462
- /* 0x00, 0x01, 0x02, 0x03 */
463
- mpidr = cpu;
464
- else if (cpu < 8)
465
- /* 0x100, 0x101, 0x102, 0x103 */
466
- mpidr = 0x100 | (cpu - 4);
467
- else
468
- pr_err("Unsupported map cpu: %d\n", cpu);
476
+ if (mpidr & MPIDR_MT_BITMASK) {
477
+ /* 0x100, 0x200, 0x300, 0x400 ... */
478
+ mpidr = (cpu & 0xff) << 8;
479
+ } else {
480
+ if (cpu < 4)
481
+ /* 0x00, 0x01, 0x02, 0x03 */
482
+ mpidr = cpu;
483
+ else if (cpu < 8)
484
+ /* 0x100, 0x101, 0x102, 0x103 */
485
+ mpidr = 0x100 | (cpu - 4);
486
+ else
487
+ pr_err("Unsupported map cpu: %d\n", cpu);
488
+ }
469489
470490 return mpidr;
471491 #else
472492 return cpu_logical_map(cpu);
473493 #endif
474494 }
495
+
496
+ulong sip_cpu_logical_map_mpidr(u32 cpu)
497
+{
498
+ return cpu_logical_map_mpidr(cpu);
499
+}
500
+EXPORT_SYMBOL_GPL(sip_cpu_logical_map_mpidr);
475501
476502 int sip_fiq_debugger_switch_cpu(u32 cpu)
477503 {
....@@ -559,6 +585,58 @@
559585 }
560586 EXPORT_SYMBOL_GPL(sip_fiq_debugger_enable_fiq);
561587
588
+int sip_fiq_control(u32 sub_func, u32 irq, unsigned long data)
589
+{
590
+ struct arm_smccc_res res;
591
+
592
+ res = __invoke_sip_fn_smc(RK_SIP_FIQ_CTRL,
593
+ sub_func, irq, data);
594
+ return res.a0;
595
+}
596
+EXPORT_SYMBOL_GPL(sip_fiq_control);
597
+
598
+int sip_wdt_config(u32 sub_func, u32 arg1, u32 arg2, u32 arg3)
599
+{
600
+ struct arm_smccc_res res;
601
+
602
+ arm_smccc_smc(SIP_WDT_CFG, sub_func, arg1, arg2, arg3,
603
+ 0, 0, 0, &res);
604
+
605
+ return res.a0;
606
+}
607
+EXPORT_SYMBOL_GPL(sip_wdt_config);
608
+
609
+int sip_hdmirx_config(u32 sub_func, u32 arg1, u32 arg2, u32 arg3)
610
+{
611
+ struct arm_smccc_res res;
612
+
613
+ arm_smccc_smc(SIP_HDMIRX_CFG, sub_func, arg1, arg2, arg3,
614
+ 0, 0, 0, &res);
615
+
616
+ return res.a0;
617
+}
618
+EXPORT_SYMBOL_GPL(sip_hdmirx_config);
619
+
620
+int sip_hdcpkey_init(u32 hdcp_id)
621
+{
622
+ struct arm_smccc_res res;
623
+
624
+ res = __invoke_sip_fn_smc(TRUSTED_OS_HDCPKEY_INIT, hdcp_id, 0, 0);
625
+
626
+ return res.a0;
627
+}
628
+EXPORT_SYMBOL_GPL(sip_hdcpkey_init);
629
+
630
+int sip_smc_mcu_config(unsigned long mcu_id,
631
+ unsigned long func,
632
+ unsigned long arg2)
633
+{
634
+ struct arm_smccc_res res;
635
+
636
+ res = __invoke_sip_fn_smc(SIP_MCU_CFG, mcu_id, func, arg2);
637
+ return res.a0;
638
+}
639
+EXPORT_SYMBOL_GPL(sip_smc_mcu_config);
562640 /******************************************************************************/
563641 #ifdef CONFIG_ARM
564642 static __init int sip_firmware_init(void)