| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bunit_bus.c $ |
|---|
| 11 | * $brcm_Revision: 3 $ |
|---|
| 12 | * $brcm_Date: 12/22/06 12:08p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Profiler suite |
|---|
| 17 | * CPU bus unit tests |
|---|
| 18 | * |
|---|
| 19 | * Revision History: |
|---|
| 20 | * |
|---|
| 21 | * $brcm_Log: /BSEAV/lib/bprofile/bunit_bus.c $ |
|---|
| 22 | * |
|---|
| 23 | * 3 12/22/06 12:08p vsilyaev |
|---|
| 24 | * PR 26715: Reformatted code |
|---|
| 25 | * |
|---|
| 26 | * 2 12/20/06 2:41p vsilyaev |
|---|
| 27 | * PR 26715: Fixed memory leak |
|---|
| 28 | * |
|---|
| 29 | * 1 12/20/06 10:44a vsilyaev |
|---|
| 30 | * PR 26715: CPU bus latency test module |
|---|
| 31 | * |
|---|
| 32 | * |
|---|
| 33 | *******************************************************************************/ |
|---|
| 34 | #include "bstd.h" |
|---|
| 35 | #include "bkni.h" |
|---|
| 36 | #include "batomic.h" |
|---|
| 37 | #include "btrc.h" |
|---|
| 38 | |
|---|
| 39 | BTRC_MODULE(bunit_bus,ENABLE); |
|---|
| 40 | |
|---|
| 41 | #define B_TEST_ROUNDS (16*1024) |
|---|
| 42 | |
|---|
| 43 | #define b_nop() __asm__ __volatile__( \ |
|---|
| 44 | ".set\tpush\n\t" \ |
|---|
| 45 | ".set\tnoreorder\n\t" \ |
|---|
| 46 | " nop \n" \ |
|---|
| 47 | " nop \n" \ |
|---|
| 48 | ".set\tpop\n") |
|---|
| 49 | |
|---|
| 50 | #define b_nop_64() \ |
|---|
| 51 | b_nop();b_nop();b_nop();b_nop(); /* 8 */ \ |
|---|
| 52 | b_nop();b_nop();b_nop();b_nop(); /* 16 */ \ |
|---|
| 53 | b_nop();b_nop();b_nop();b_nop(); /* 24 */ \ |
|---|
| 54 | b_nop();b_nop();b_nop();b_nop(); /* 32 */ \ |
|---|
| 55 | b_nop();b_nop();b_nop();b_nop(); /* 40 */ \ |
|---|
| 56 | b_nop();b_nop();b_nop();b_nop(); /* 48 */ \ |
|---|
| 57 | b_nop();b_nop();b_nop();b_nop(); /* 56 */ \ |
|---|
| 58 | b_nop();b_nop();b_nop();b_nop() /* 64 */ |
|---|
| 59 | |
|---|
| 60 | static void |
|---|
| 61 | b_test_read(volatile uint32_t *ptr, uint32_t val) |
|---|
| 62 | { |
|---|
| 63 | unsigned i; |
|---|
| 64 | BSTD_UNUSED(val); |
|---|
| 65 | |
|---|
| 66 | for(i=0;i<B_TEST_ROUNDS;i++) { |
|---|
| 67 | *ptr; |
|---|
| 68 | *ptr; |
|---|
| 69 | *ptr; |
|---|
| 70 | *ptr; |
|---|
| 71 | |
|---|
| 72 | *ptr; |
|---|
| 73 | *ptr; |
|---|
| 74 | *ptr; |
|---|
| 75 | *ptr; |
|---|
| 76 | |
|---|
| 77 | *ptr; |
|---|
| 78 | *ptr; |
|---|
| 79 | *ptr; |
|---|
| 80 | *ptr; |
|---|
| 81 | |
|---|
| 82 | *ptr; |
|---|
| 83 | *ptr; |
|---|
| 84 | *ptr; |
|---|
| 85 | *ptr; |
|---|
| 86 | } |
|---|
| 87 | return; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | static void |
|---|
| 91 | b_test_write(volatile uint32_t *ptr, uint32_t val) |
|---|
| 92 | { |
|---|
| 93 | unsigned i; |
|---|
| 94 | |
|---|
| 95 | for(i=0;i<B_TEST_ROUNDS;i++) { |
|---|
| 96 | *ptr=val; |
|---|
| 97 | *ptr=val; |
|---|
| 98 | *ptr=val; |
|---|
| 99 | *ptr=val; |
|---|
| 100 | |
|---|
| 101 | *ptr=val; |
|---|
| 102 | *ptr=val; |
|---|
| 103 | *ptr=val; |
|---|
| 104 | *ptr=val; |
|---|
| 105 | |
|---|
| 106 | *ptr=val; |
|---|
| 107 | *ptr=val; |
|---|
| 108 | *ptr=val; |
|---|
| 109 | *ptr=val; |
|---|
| 110 | |
|---|
| 111 | *ptr=val; |
|---|
| 112 | *ptr=val; |
|---|
| 113 | *ptr=val; |
|---|
| 114 | *ptr=val; |
|---|
| 115 | } |
|---|
| 116 | return ; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | static void |
|---|
| 120 | b_test_write_delay(volatile uint32_t *ptr, uint32_t val) |
|---|
| 121 | { |
|---|
| 122 | unsigned i; |
|---|
| 123 | |
|---|
| 124 | for(i=0;i<B_TEST_ROUNDS;i++) { |
|---|
| 125 | *ptr=val; |
|---|
| 126 | b_nop_64(); |
|---|
| 127 | *ptr=val; |
|---|
| 128 | b_nop_64(); |
|---|
| 129 | *ptr=val; |
|---|
| 130 | b_nop_64(); |
|---|
| 131 | *ptr=val; |
|---|
| 132 | b_nop_64(); |
|---|
| 133 | |
|---|
| 134 | *ptr=val; |
|---|
| 135 | b_nop_64(); |
|---|
| 136 | *ptr=val; |
|---|
| 137 | b_nop_64(); |
|---|
| 138 | *ptr=val; |
|---|
| 139 | b_nop_64(); |
|---|
| 140 | *ptr=val; |
|---|
| 141 | b_nop_64(); |
|---|
| 142 | |
|---|
| 143 | *ptr=val; |
|---|
| 144 | b_nop_64(); |
|---|
| 145 | *ptr=val; |
|---|
| 146 | b_nop_64(); |
|---|
| 147 | *ptr=val; |
|---|
| 148 | b_nop_64(); |
|---|
| 149 | *ptr=val; |
|---|
| 150 | b_nop_64(); |
|---|
| 151 | |
|---|
| 152 | *ptr=val; |
|---|
| 153 | b_nop_64(); |
|---|
| 154 | *ptr=val; |
|---|
| 155 | b_nop_64(); |
|---|
| 156 | *ptr=val; |
|---|
| 157 | b_nop_64(); |
|---|
| 158 | *ptr=val; |
|---|
| 159 | b_nop_64(); |
|---|
| 160 | } |
|---|
| 161 | return ; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | static void |
|---|
| 165 | b_unit_bus_run(const char *name, volatile uint32_t *ptr, void (*test)(volatile uint32_t *ptr, uint32_t val)) |
|---|
| 166 | { |
|---|
| 167 | unsigned i; |
|---|
| 168 | BKNI_EnterCriticalSection(); |
|---|
| 169 | for(i=0;i<5;i++) { |
|---|
| 170 | uint32_t val = *ptr; |
|---|
| 171 | BTRC_TRACE(bunit_bus, START); |
|---|
| 172 | test(ptr, val); |
|---|
| 173 | BTRC_TRACE(bunit_bus, STOP); |
|---|
| 174 | } |
|---|
| 175 | BKNI_LeaveCriticalSection(); |
|---|
| 176 | BKNI_Printf("test '%s' addr %#x\n", name, (unsigned)ptr); |
|---|
| 177 | BTRC_Module_Report(BTRC_MODULE_HANDLE(bunit_bus)); |
|---|
| 178 | BTRC_Module_Reset(BTRC_MODULE_HANDLE(bunit_bus)); |
|---|
| 179 | BKNI_Sleep(50); |
|---|
| 180 | return; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | void |
|---|
| 184 | bunit_bus(void) |
|---|
| 185 | { |
|---|
| 186 | void *addr = BKNI_Malloc(4); /* we use malloced memory because it would go from the KSEG0 (static memory is from KSEG2, and MMU mapped) */ |
|---|
| 187 | volatile uint32_t *ptr = addr; |
|---|
| 188 | BDBG_ASSERT(addr); |
|---|
| 189 | |
|---|
| 190 | b_unit_bus_run("b_test_read/cached", ptr, b_test_read); |
|---|
| 191 | b_unit_bus_run("b_test_write/cached", ptr, b_test_write); |
|---|
| 192 | b_unit_bus_run("b_test_write_delay/cached", ptr, b_test_write_delay); |
|---|
| 193 | |
|---|
| 194 | ptr = (uint32_t *)(0x20000000|(uint32_t)addr); |
|---|
| 195 | |
|---|
| 196 | b_unit_bus_run("b_test_read/uncached", ptr, b_test_read); |
|---|
| 197 | b_unit_bus_run("b_test_write/uncached", ptr, b_test_write); |
|---|
| 198 | b_unit_bus_run("b_test_write_delay/uncached", ptr, b_test_write_delay); |
|---|
| 199 | |
|---|
| 200 | ptr = (uint32_t *)0xB0082ffc; |
|---|
| 201 | b_unit_bus_run("b_test_read/ENET_TOP_Descriptor", ptr, b_test_read); |
|---|
| 202 | b_unit_bus_run("b_test_write/ENET_TOP_Descriptor", ptr, b_test_write); |
|---|
| 203 | b_unit_bus_run("b_test_write_delay/ENET_TOP_Descriptor", ptr, b_test_write_delay); |
|---|
| 204 | |
|---|
| 205 | BKNI_Free(addr); |
|---|
| 206 | return; |
|---|
| 207 | } |
|---|
| 208 | |
|---|