dp_test.c 10.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
/**********************************************
 *
 * dp_test.c
 *
 * Collection of DP tests for IOSIM
 *
 **********************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/times.h>
#include <PR/ultratypes.h>
#include "PR/bcp.h"
#include "simipc.h"
#include "iomap.h"
#include "bcptest.h"
#include "bcp_util.h"
#include "simipc.h"
#include "PR/verify.h"
#include "PR/mbi.h"
#include "PR/gbi.h"
#include "sys/stat.h"
#include "unistd.h"
#include "fcntl.h"

#define FAIL -1
#define PASS 0

/*
 * These are from rdpvector
 */
#define ZBUFFER_ADDR	0x00280000 /* hard coded as per rdpvector's spec file */
#define CFB0_ADDR	0x00380000 /* hard coded as per rdpvector's spec file */
#define CFB1_ADDR	0x003a5800 /* hard coded as per rdpvector's spec file */
#define RDPLIST_ADDR	0x00000a00 /* placed above verifyInfo in 1st MB of ram*/


static void block_read(int nwords, int addr, int *data)
{
    int j;
    V_INT vdata[nwords];
    PV_INT pvdata = &vdata[0];

    BD_V_IO_BREAD(addr, nwords*4, 0, pvdata);

    for (j=0; j<nwords; j++) {
        data[j] = vdata[j].data_part;
    }

}

static unsigned long long
computeChecksum(VerifyInfo *v)
{
    unsigned long  longPixels;
    unsigned long long checksumValue;
    int row, column;
    unsigned int x;
    unsigned int *fb;
    unsigned int *fbp;
    int n_blocks;
    int i;

    /*
     * Only spin cycles to compute/compare the checksum upon user request.
     */
    longPixels = v->frameBuffer0Addr;
    checksumValue = 0;
    fb = (int *) malloc(v->height*v->width*4 + 32);

    /*
     * Grab the framebuffer using block reads always grab 32 bits
     */
    n_blocks = ((v->height * v->width * 4) + 31) / 32;
    fprintf(LogFp, "N blocks %d\n", n_blocks);
    for (i=0; i<n_blocks; i++) {
        block_read(8, longPixels + i*32, fb + i*8);
    }

    if (v->frameBufferSize == G_IM_SIZ_16b ) {
        fprintf(LogFp, "16 bit pixels at 0x%lx width %d height %d\n", longPixels, v->width, v->height);
        fbp = fb;
        for (row = 0; row < v->height; row++) {
            for (column = 0; column < v->width; column+=2) {
                x = *fbp++;
                checksumValue += (x >> 16) + (x & 0xffff);
                longPixels += 4;
            }
        }
    } else if (v->frameBufferSize == G_IM_SIZ_32b ) {
        fprintf(LogFp, "32 bit pixels at 0x%lx width %d height %d\n", longPixels, v->width, v->height);
        fbp = fb;
        for (row = 0; row < v->height; row++) {
            for (column = 0; column < v->width; column++) {
                x = *fbp++;
                checksumValue += x;
                longPixels += 4;
            }
        }
    } else {
        /*
         * 1024 x 1024 framebuffer renders in 32 bits.
         */
        fprintf(LogFp, "32 bit pixels, 1024 fb at 0x%lx\n", longPixels);
        fbp = fb;
        for (row = 0; row < 1024; row++) {
            for (column = 0; column < 1024; column++) {
                x = *fbp++;
                checksumValue += x;
                longPixels += 4;
            }
        }
        
    }
    free(fb);
    return checksumValue;
}

int dp_list(int do_checksum, unsigned long long cs)
{
    int start_addr = 0;
    int end_addr;
    int count;
    int x;
    unsigned long long cs;
    int i;
    int n_failures = 0;
    VerifyInfo v_info;
    int *p;
    fprintf(LogFp, "DP Test\n");

    InitDDR(0, 0, 0, 0);

    /*
     * Dump out information from Verify info structure
     */
    fprintf(LogFp, "Verify Info\n");
    p = (int *) &v_info;
    for (i=0; i<sizeof(VerifyInfo); i+=4) {
        x = IO_READ(VERIFY_INFO_PHYSADDR+i);
        *p++ = x;
    }
    fprintf(LogFp, "DP List addr 0x%x\n", v_info.rdpListAddr);
    fprintf(LogFp, "CFB 0 addr 0x%x\n", v_info.frameBuffer0Addr);
    fprintf(LogFp, "CFB 1 addr 0x%x\n", v_info.frameBuffer1Addr);
    fflush(LogFp);

    if (!do_checksum) {
        /*
         * Count the commands to full sync
         */
        start_addr = v_info.rdpListAddr;
        count = 0;
        do {
            x = IO_READ(start_addr) >> 24;
            start_addr += 8;
            count++;
            if (count > 10000) {
                break;
            }
        } while (x != G_RDPFULLSYNC);
        fprintf(LogFp, "Number of Display list commands %d\n", count);
        fflush(LogFp);

        /*
         * Start the DP
         */
        start_addr = v_info.rdpListAddr;
        IO_WRITE(DPC_START_REG,  start_addr);
        IO_WRITE(DPC_END_REG, start_addr + count*8);  
        end_addr = IO_READ(DPC_END_REG);
        fprintf(LogFp, "end reg 0x%x\n", end_addr);

        /* status read */
        x = IO_READ(DPC_STATUS_REG);
        fprintf(LogFp, "Status register: 0x%x\n", x);

        do {
            BCP_STALL(1000);
            x = IO_READ(DPC_CURRENT_REG);
            fprintf(LogFp, "Current 0x%x\n", x);
            fprintf(LogFp, "Status register: 0x%x\n", IO_READ(DPC_STATUS_REG));
        } while (x != end_addr);

        fprintf(LogFp, "Waiting for Pipe to clear\n");
        do {
            BCP_STALL(1000);
            x = IO_READ(DPC_STATUS_REG);
            fprintf(LogFp, "Status 0x%x\n", x);
        } while (x & DPC_STATUS_PIPE_BUSY);
    }

    /*
     * Now calculate the checksum
     */
    cs = computeChecksum(&v_info);
    fprintf(LogFp, "Checksum is: 0x%llx\n", cs);

    if (n_failures > 0) {
        return FAIL;
    } else {
        return PASS;
    }
}

int dp_list_file(char *file)
{
    FILE *fd;
    int start_addr = 0;
    int end_addr;
    int count;
    int i;
    struct stat statBuf;
    Gfx pkt;
    VerifyInfo v;
    u32 *pv;
    u32 w;
    int dram_addr;
    int x;

    fprintf(LogFp, "DP Test from file\n");

    InitDDR(0, 0, 0, 0);

    if ((fd = fopen(file, "r")) == NULL) {
        fprintf(LogFp, "No file\n");
        return FAIL;
    }

    stat(file, &statBuf);
    count = statBuf.st_size;
    fprintf(LogFp, "File size %d\n", count);

    /*
     * Copy into DRAM
     */
    dram_addr = 0;
    for (i=0; i<count/4; i++) {
        fread(&w, 4, 1, fd);
        IO_WRITE(dram_addr, htonl(w));
        w = IO_READ(dram_addr);
        fprintf(LogFp, "Addr 0x%x data 0x%x\n", dram_addr, w);
        dram_addr+=4;
    }

    /*
     * Add a full sync to the end
     */
    gDPFullSync(&pkt);
    IO_WRITE(dram_addr, pkt.words.w0);
    IO_WRITE(dram_addr+4, pkt.words.w1);
    count += 8;

    fflush(LogFp);

    start_addr = 0;
    count = count / 8;
    fprintf(LogFp, "Number of Display list commands %d\n", count);
    fflush(LogFp);

    memset(&v, 0, sizeof(v));
    v.rdpListAddr = 0;
    v.width = 240;
    v.height = 320;
    v.frameBuffer0Addr = 0x29650;
    v.magicNumber = MAGICNUMBER;
    v.version = VERSION;
    v.frameBufferFormat = G_IM_FMT_RGBA;
    v.frameBufferSize = G_IM_SIZ_16b;

    pv = (u32 *) &v;
    for (i=0; i<sizeof(VerifyInfo); i+=4) {
        IO_WRITE(VERIFY_INFO_PHYSADDR+i, *pv++);
    }

    /*
     * Start the DP
     */
    start_addr = 0;
    IO_WRITE(DPC_START_REG,  start_addr);
    IO_WRITE(DPC_END_REG, start_addr + count*8);  
    end_addr = IO_READ(DPC_END_REG);
    fprintf(LogFp, "end reg 0x%x\n", end_addr);

    /* status read */
    x = IO_READ(DPC_STATUS_REG);
    fprintf(LogFp, "Status register: 0x%x\n", x);

    do {
        BCP_STALL(1000);
        x = IO_READ(DPC_CURRENT_REG);
        fprintf(LogFp, "Current 0x%x\n", x);
        fprintf(LogFp, "Status register: 0x%x\n", IO_READ(DPC_STATUS_REG));
    } while (x != end_addr);

    fprintf(LogFp, "Waiting for Pipe to clear\n");
    do {
        BCP_STALL(1000);
        x = IO_READ(DPC_STATUS_REG);
        fprintf(LogFp, "Status 0x%x\n", x);
    } while (x & DPC_STATUS_PIPE_BUSY);

}


int dp_list_file_xbus(char *file)
{
    FILE *fd;
    FILE *mc;
    int start_addr = 0;
    int end_addr;
    int count;
    int i;
    struct stat statBuf;
    Gfx pkt;
    VerifyInfo v;
    u32 *pv;
    u32 w;
    int dram_addr;
    int x;

    fprintf(LogFp, "DP Test from file using xbus\n");

    /*
     * Load microcode
     */
    stat("xbus", &statBuf);
    count = statBuf.st_size;
    fprintf(LogFp, "Microcode File size %d\n", count);
    mc = fopen("xbus", "r");
    /*
     * Copy into IMEM
     */
    dram_addr = SP_IMEM_START;
    for (i=0; i<count/4; i++) {
        fread(&w, 4, 1, mc);
        IO_WRITE(dram_addr, htonl(w));
        w = IO_READ(dram_addr);
        fprintf(LogFp, "Addr 0x%x data 0x%x\n", dram_addr, w);
        dram_addr+=4;
    }

    InitDDR(0, 0, 0, 0);

    if ((fd = fopen(file, "r")) == NULL) {
        fprintf(LogFp, "No file\n");
        return FAIL;
    }

    stat(file, &statBuf);
    count = statBuf.st_size;
    fprintf(LogFp, "File size %d\n", count);

    /*
     * Copy into DMEM
     */
    dram_addr = SP_DMEM_START + 0x10;
    for (i=0; i<count/4; i++) {
        fread(&w, 4, 1, fd);
        IO_WRITE(dram_addr, htonl(w));
        w = IO_READ(dram_addr);
        fprintf(LogFp, "Addr 0x%x data 0x%x\n", dram_addr, w);
        dram_addr+=4;
    }

    /*
     * Add a full sync to the end
     */
    gDPFullSync(&pkt);
    IO_WRITE(dram_addr, pkt.words.w0);
    IO_WRITE(dram_addr+4, pkt.words.w1);
    count += 8;

    fflush(LogFp);

    start_addr = SP_DMEM_START + 0x10;
    count = count / 8;
    fprintf(LogFp, "Number of Display list commands %d\n", count);
    fflush(LogFp);

    memset(&v, 0, sizeof(v));
    v.rdpListAddr = 0;
    v.width = 240;
    v.height = 320;
    v.frameBuffer0Addr = 0x29650;
    v.magicNumber = MAGICNUMBER;
    v.version = VERSION;
    v.frameBufferFormat = G_IM_FMT_RGBA;
    v.frameBufferSize = G_IM_SIZ_16b;

    pv = (u32 *) &v;
    for (i=0; i<sizeof(VerifyInfo); i+=4) {
        IO_WRITE(VERIFY_INFO_PHYSADDR+i, *pv++);
    }

    /*
     * Write the start and end into DMEM
     */
    start_addr = SP_DMEM_START+0x10;
    IO_WRITE(SP_DMEM_START,  start_addr);
    IO_WRITE(SP_DMEM_START+4, start_addr + count*8);  

    /* status read */
    x = IO_READ(DPC_STATUS_REG);
    fprintf(LogFp, "Status register: 0x%x\n", x);

    /*
     * Write the SP status register to set the signal 2 bit, which starts the process
     */
    IO_WRITE(SP_STATUS_REG, SP_SET_HALT);
    IO_WRITE(SP_PC_REG, SP_IMEM_START);
    IO_WRITE(SP_STATUS_REG, SP_SET_SIG0 | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT);
    do {
        x = IO_READ(SP_PC_REG);
        fprintf(LogFp, "SP PC register 0x%x\n", x);
        x = IO_READ(SP_STATUS_REG);
        fprintf(LogFp, "SP status register 0x%x\n", x);
    } while (x & SP_STATUS_SIG0);
    fprintf(LogFp, "DP should have started\n");

    end_addr = IO_READ(DPC_END_REG);
    fprintf(LogFp, "end reg 0x%x\n", end_addr);

    do {
        BCP_STALL(1000);
        x = IO_READ(DPC_CURRENT_REG);
        fprintf(LogFp, "Current 0x%x\n", x);
        fprintf(LogFp, "Status register: 0x%x\n", IO_READ(DPC_STATUS_REG));
    } while (x != end_addr);

    fprintf(LogFp, "Waiting for Pipe to clear\n");
    do {
        BCP_STALL(1000);
        x = IO_READ(DPC_STATUS_REG);
        fprintf(LogFp, "Status 0x%x\n", x);
    } while (x & DPC_STATUS_PIPE_BUSY);

}