1 #include <linux/kernel.h>
2 #include <linux/device.h>
3 #include <linux/platform_device.h>
4 #include <linux/module.h>
5 #include <mach/mt_mcu.h>
6 #include <mach/mt_reg_base.h>
7 #include <asm/system.h>
8 #include <linux/module.h>
9 #include <linux/uaccess.h>
10 #include <linux/vmalloc.h>
11 #include <linux/slab.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/cpu.h>
15 #include <linux/smp.h>
20 #define dbg_printk printk
24 extern void smp_inner_dcache_flush_all();
26 static struct mt_mcu_driver
{
27 struct device_driver driver
;
28 const struct platform_device_id
*id_table
;
31 static struct mt_mcu_driver mt_mcu_drv
= {
34 .bus
= &platform_bus_type
,
41 #define BUFF_LEN (1024*1024)
43 static int ts_emi_access(void){
44 unsigned int *test_array_v
;
45 unsigned int *test_array_p
;
47 test_array_v
= dma_alloc_coherent(NULL
, sizeof(unsigned int ) * BUFF_LEN
/sizeof(unsigned int), &test_array_p
, GFP_KERNEL
);
49 for(i
= 0; i
< BUFF_LEN
/sizeof(unsigned int); i
++)
53 static int ts_tran_count(void){
55 printk("in %s",__FUNCTION__
);
56 /* set up performance counter */
59 printk("in testcases:MCU_BIU_EVENT0_CNT=%x,MCU_BIU_EVENT1_CNT:%x\n",*((unsigned int *) MCU_BIU_EVENT0_CNT
),*((unsigned int *) MCU_BIU_EVENT1_CNT
));
60 *((unsigned int *) MCU_BIU_EVENT0_SEL
) = 0x2; //AC_R snoop transaction count MCU->CPU
61 //*((unsigned int *) MCU_EVENT1_SEL) = 0x4; //AC_R snoop hit
62 *((unsigned int *) MCU_BIU_EVENT1_SEL
) = 0x0; // DMA->MCU
63 *((unsigned int *) MCU_BIU_EVENT0_CON
) = 0x1; // enable counter 0
64 *((unsigned int *) MCU_BIU_EVENT1_CON
) = 0x1; // enable counter 1
65 *((unsigned int *) MCU_BIU_PMCR
) |= 0x2; // retset perf counter
66 *((unsigned int *) MCU_BIU_PMCR
) &= ~0x2; // reset performance counter
69 /* Invoke 4 cores concurrent write to EMI with 1MB data set per core. */
71 on_each_cpu(ts_emi_access
, NULL
, false);
73 /* check performance counter */
74 printk("in testcases:MCU_EVENT0_CNT=%x,MCU_EVENT1_CNT:%x\n",*((unsigned int *) MCU_BIU_EVENT0_CNT
),*((unsigned int *) MCU_BIU_EVENT1_CNT
));
79 * mci_dvt_show: To show usage.
81 static ssize_t
mcu_dvt_show(struct device_driver
*driver
, char *buf
)
83 return snprintf(buf
, PAGE_SIZE
, "MCU dvt test\n");
87 * mci_dvt_store: To select mci test case.
89 static ssize_t
mcu_dvt_store(struct device_driver
*driver
, const char *buf
,
92 char *p
= (char *)buf
;
95 num
= simple_strtoul(p
, &p
, 10);
111 DRIVER_ATTR(mcu_dvt
, 0664, mcu_dvt_show
, mcu_dvt_store
);
113 int mt_mcu_init(void){
114 volatile unsigned int reg_val
;
116 dbg_printk("[MCU] MCU init...\n");
118 /* enable Out of order*/
119 reg_val
= readl(MCU_BIU_CON
);
121 writel(reg_val
, MCU_BIU_CON
);
126 reg_val
= readl(MCU_BIU_CON
);
127 reg_val
|= (0x1 << 0x8);
128 writel(reg_val
, MCU_BIU_CON
);
133 /* enable MCU_BIU DCM function*/
134 reg_val
= readl(MCU_BIU_CON
);
135 reg_val
|= (0x1 << 12);
136 writel(reg_val
, MCU_BIU_CON
);
140 /* enable MCUSYS DCM function */
141 reg_val
= readl(MCUSYS_CA7_MISC_CONFIG
);
142 reg_val
|= (0x1 << 9);
143 writel(reg_val
, MCUSYS_CA7_MISC_CONFIG
);
147 /*PC / FP / SP trapper */
148 dbg_printk("CPU0-PC:0x%x,CPU1-PC:0x%x,CPU2-PC:0x%x,CPU3-PC:0x%x\n",readl(MCUSYS_DBG_CORE0_PC
),readl(MCUSYS_DBG_CORE1_PC
),readl(MCUSYS_DBG_CORE2_PC
),readl(MCUSYS_DBG_CORE3_PC
));
149 dbg_printk("CPU0-FP:0x%x,CPU1-FP:0x%x,CPU2-FP:0x%x,CPU3-FP:0x%x\n",readl(MCUSYS_DBG_CORE0_FP
),readl(MCUSYS_DBG_CORE1_FP
),readl(MCUSYS_DBG_CORE2_FP
),readl(MCUSYS_DBG_CORE3_FP
));
150 dbg_printk("CPU0-SP:0x%x,CPU1-SP:0x%x,CPU2-SP:0x%x,CPU3-SP:0x%x\n",readl(MCUSYS_DBG_CORE0_SP
),readl(MCUSYS_DBG_CORE1_SP
),readl(MCUSYS_DBG_CORE2_SP
),readl(MCUSYS_DBG_CORE3_SP
));
152 ret
= driver_register(&mt_mcu_drv
.driver
);
154 ret
= driver_create_file(&mt_mcu_drv
.driver
, &driver_attr_mcu_dvt
);
157 dbg_printk("MCU init done...\n");
161 int mt_mcu_exit(void){
166 module_init(mt_mcu_init
);
167 module_exit(mt_mcu_exit
);