bandwidth.c 1.85 KB
#include "cpusim.h"

#define CMEM_WORD	(*(vu32*)K0BASE)
#define UMEM_WORD	(*(vu32*)K1BASE)

#define CMEM64_WORD	(*(vu32*)PHYS_TO_K0(DDRRAM64_START))
#define UMEM64_WORD	(*(vu32*)PHYS_TO_K1(DDRRAM64_START))

#define CNONMEM_WORD	(*(vu32*)PHYS_TO_K0(PI_BUFFER_BASE_REG))
#define UNONMEM_WORD	(*(vu32*)PHYS_TO_K1(PI_BUFFER_BASE_REG))

void
failed(const char* code) {
    message("bandwidth test failed (");
    message(code);
    message(")\n");
    DBG_JTAG_FAIL(code);
    test_postamble();
}

int
main() {
    int x;
    vu32 *p0, *p1;
    void (*f0)(void);
    static void run(void);

    if (((getcp0reg(C0_CONFIG)&CONFIG_EC) >> 28) != 1)
	IO_WRITE(MI_CTRL_REG, MI_CTRL_HARD_RESET|MI_CTRL_DIV_MODE_1_5);

    test_preamble();

    initICache();
    initDCache();
    init_ddr();

    setcp0reg(C0_SR, SR_CU0|SR_CU1|SR_BEV);
    setcp0reg(C0_CONFIG, CONFIG_BE|CONFIG_NONCOHRNT);
    p0 = (vu32*)run;
    p1 = (vu32*)PHYS_TO_K1(INTERNAL_RAM_START);
    f0 = (void(*))K1_TO_K0(p1);
    for(x = 0; x < 256; x++) *p1++ = *p0++;
    (*f0)();

    message("bandwidth test\n");
    DBG_JTAG_PASS("Bandwidth test Passed\n");
    test_postamble();
    return 0;
}

#define STRIDE	(1*1024)
static void
run(void) {
    int i, pass = 0;
    u32* x = (u32*)&UMEM_WORD;
    u32* y = (u32*)&UMEM_WORD+STRIDE;
    unsigned z;
again:
    i = STRIDE;
    z = getcp0reg(C0_COUNT);
    do {
	*x++ = 0;
    } while(i-- >= 0);
    IO_WRITE(PI_IDE3_BASE_REG, getcp0reg(C0_COUNT)-z);

    i = STRIDE; x = y - STRIDE;
    z = getcp0reg(C0_COUNT);
    do {
	*(volatile unsigned *)x++;
    } while(i-- >= 0);
    IO_WRITE(PI_IDE3_BASE_REG, getcp0reg(C0_COUNT)-z);

    i = STRIDE; x = y - STRIDE;
    z = getcp0reg(C0_COUNT);
    do {
	*y++ = *x++;
    } while(i-- > 0);
    IO_WRITE(PI_IDE3_BASE_REG, getcp0reg(C0_COUNT)-z);

    if (pass++ == 0) {
	x = (u32*)&CMEM_WORD;
	y = (u32*)&CMEM_WORD+STRIDE;
	goto again;
    }
}