home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / mondello / clgd5470.c next >
C/C++ Source or Header  |  1996-05-27  |  11KB  |  363 lines

  1. /* 
  2.  
  3.    file: clgd5470.c
  4.    
  5. */
  6.  
  7. #include "mondello/compiler.h"
  8. #include "mondello/clgd5470.h"
  9. #include "mondello/clgd5471.h"
  10. #include "mondello/clgd547x.h"
  11. #include "mondello/davinci.h"
  12.  
  13. /* exported globals */
  14.  
  15. unsigned int *clgd5470LogicalBase;
  16. unsigned int *clgd5470LogicalBase2;
  17.  
  18. unsigned int listStart=0;
  19.  
  20. #define MAXINSTR 4096;  /* 4096 bytes is maximum instruction length   */
  21. unsigned int *listPtr;    /* where next instruction is to be written    */ 
  22. unsigned int *listMax;    /* threshold for starting execution of instrs */
  23. unsigned int listNum;   /* list number being written to               */
  24. unsigned int *listPtr0; /* base of list 0                             */
  25. unsigned int *listMax0; /* threshold of list 0                        */
  26. unsigned int *listPtr1; /* base of list 1                             */
  27. unsigned int *listMax1; /* threshold of list 1                        */
  28.  
  29. /*----------------------------------------------------------------------------
  30.   inWarp(addr) reads a long from the Warp chip at address addr
  31. -----------------------------------------------------------------------------*/
  32. int inWarp(int address) 
  33. {
  34.   return *(unsigned int*)(clgd547xLogicalBase + 0x3ffd00 + (address << 2));
  35. }
  36.  
  37. /*----------------------------------------------------------------------------
  38.   outWarp(addr) writes a long to the Warp chip at address addr
  39. -----------------------------------------------------------------------------*/
  40. void outWarp(int address, unsigned int data)
  41. {
  42.   BYTE* addr;
  43.   addr=(BYTE*)clgd547xLogicalBase;
  44.   addr=addr+0x3ffc00;
  45.   addr=addr+(address << 2);
  46.   *((unsigned int*)addr)=data; 
  47. /*  *(clgd547xLogicalBase + (0x3ffc00) + (address << 2)) = data; */
  48. }
  49.  
  50. void dumpMem(int address, int range) 
  51. {
  52.   int i;
  53.   BYTE ch;
  54.   BYTE *t=(BYTE*)(((unsigned int)clgd547xLogicalBase)+address);
  55.   for(i=0; i<range; i++) {
  56.     ch=*t++;
  57.     if ((ch>' ') && (ch<128)) {
  58.       printf("%.2x %c -- ",ch,ch);
  59.     }
  60.     else
  61.       printf("%.2x . -- ",ch);
  62.   }
  63.   printf("\n");
  64. }
  65.  
  66. void wm(unsigned int *x)
  67. {
  68.   printf("%8x\n",*x);
  69. }
  70.  
  71. void writem(unsigned int *x, int val)
  72. {
  73.   *x=val;
  74. }
  75.  
  76. void debugWarp() 
  77. {
  78.   printf("control register      %8X %d\n",inWarp(0x20),inWarp(0x20));
  79.   printf("scratch register      %8X %d\n",inWarp(0x21),inWarp(0x21));
  80.   printf("mask a register       %8X %d\n",inWarp(0x22),inWarp(0x22));  
  81.   printf("mask b register       %8X %d\n",inWarp(0x23),inWarp(0x23));
  82.   printf("status                %8X %d\n",inWarp(0x24),inWarp(0x24));
  83. /*  printf("bank enable register  %8X %d\n",inWarp(),inWarp());
  84.   printf("bank mask register    %8X %d\n",inWarp(),inWarp());
  85.   printf("bank compare register %8X %d\n",inWarp(),inWarp()); */
  86.   printf("R1      %8X %8d  ",inWarp(0x28),inWarp(0x28));
  87.   printf("R2      %8X %8d\n",inWarp(0x29),inWarp(0x29));
  88.   printf("R3      %8X %8d  ",inWarp(0x2A),inWarp(0x2A));
  89.   printf("R4      %8X %8d\n",inWarp(0x2B),inWarp(0x2B));
  90.   printf("R5      %8X %8d  ",inWarp(0x2C),inWarp(0x2C));
  91.   printf("R6      %8X %8d\n",inWarp(0x2D),inWarp(0x2D));
  92.   printf("R7      %8X %8d  ",inWarp(0x2E),inWarp(0x2E));
  93.   printf("R8      %8X %8d\n",inWarp(0x2F),inWarp(0x2F));
  94.   printf("R9      %8X %8d  ",inWarp(0x30),inWarp(0x30));
  95.   printf("R10     %8X %8d\n",inWarp(0x31),inWarp(0x31));
  96.   printf("R11     %8X %8d  ",inWarp(0x32),inWarp(0x32));
  97.   printf("R12     %8X %8d\n",inWarp(0x33),inWarp(0x33));
  98.   printf("R13     %8X %8d  ",inWarp(0x34),inWarp(0x34));
  99.   printf("R14     %8X %8d\n",inWarp(0x35),inWarp(0x35));
  100.   printf("R15     %8X %8d  ",inWarp(0x36),inWarp(0x36));
  101.   printf("R16     %8X %8d\n",inWarp(0x37),inWarp(0x37));
  102.   printf("R17     %8X %8d  ",inWarp(0x38),inWarp(0x38));
  103.   printf("R18     %8X %8d\n",inWarp(0x39),inWarp(0x39));
  104. }
  105.  
  106. int test5470IO()
  107. {
  108.   int i;
  109.   int errors=0;
  110.  
  111.   for (i=0x28; i<0x3a; i++) {
  112.     outWarp(i,i);
  113.   }
  114.  
  115.   for (i=0x28; i<0x3a; i++) {
  116.     if(inWarp(i)!=i) errors++;
  117.   }
  118.  
  119.   for (i=0x28; i<0x3a; i++) {
  120.     outWarp(i,0);
  121.   }
  122.   return errors;
  123. }
  124.  
  125. void testLoc(unsigned int *loc)
  126. {
  127.   int i=0;
  128.   int done=0;
  129.   int errors;
  130.     
  131.   while(!done) {
  132.     *loc=i;
  133.     if (*loc!=i) {
  134.       printf(" test failed for %d\n",i);
  135.       errors++;
  136.       if (errors>20) done=1;
  137.     }
  138.     if (i==0xFFFFFFFF) {
  139.       done=1;
  140.     }  
  141.     i++;
  142.   }
  143. }
  144.  
  145. /*-----------------------------------------------------------------------------
  146.   clgd5470Init - enable the 5470, then bring it into a reasonable mode
  147. -----------------------------------------------------------------------------*/
  148. void clgd5470Init(int bpp) {
  149.   int i,status;
  150.   BYTE *t;
  151.        
  152.   clgd5470LogicalBase=(unsigned int*)clgd547xLogicalBase;
  153.   
  154.   printf("init5470: entering\n");
  155.   
  156.   /* bring Warp out of reset */
  157.   printf("init5470: enabling 5470\n");
  158.  
  159.   iopl(3);
  160.   outGraph(0xD078);
  161.   *clgd5470LogicalBase=0xffffffff;
  162.   status=*clgd5470LogicalBase;
  163.   outGraph(0xD038);
  164.   iopl(0);  
  165.  
  166.   sleep(1);
  167.   if(inWarp(CONTROL_REG) & 0x00800000) {
  168.     printf("5470 ok\n");
  169.   }
  170.   else {
  171.     printf("failure to initialize 5470\n");
  172.   }
  173.  
  174.   printf("init5470: 5470 IO Reg results: %d\n",test5470IO());
  175.  
  176.   printf("init5470: initializing 5470 video information\n");
  177.  
  178.   /* open up everything for modification */
  179.   outWarp(MASK_B_REG,0xfDffffff);  
  180.   outWarp(MASK_REG,0xffffffff);   
  181.  
  182.   /* outWarp(REF0_REG,0x00800000); */ /* 12/24 bpp modes */ 
  183.   outWarp(REF0_REG,0x00800000);    /* 0x00000000 */ /* 8 bpp */
  184.   outWarp(REF1_REG,0x00000000);    /* 0x00000800 */ /* set screen start addr = */ 
  185.   outWarp(MASK_REG,0x00000000);
  186.   outWarp(REF0_REG,0x61000000);
  187.   outWarp(REF1_REG,0x00000000);
  188.  
  189.   outWarp(REF2_REG,0x00000400);    /* non db 8bpp */
  190.   outWarp(REF3_REG,0x00000000);    /* set cursor base address */ 
  191.   outWarp(REF4_REG,0x00000000);    /* set screen start time */
  192.   outWarp(REF5_REG,      1200);    /* set screen end time */
  193.   outWarp(REF6_REG,0x00000000);    /* set hw window start time */
  194.   outWarp(REF7_REG,      1200);    /* set hw window end time */
  195.   outWarp(REF8_REG,0x00000000);    /* set csr start time */
  196.   outWarp(REF9_REG,0x00000000);    /* set csr end time */
  197.   outWarp(REFA_REG,279);           /* 479 */ /* Wait timer end line */
  198.   outWarp(REFB_REG,887); /*(int)(10e-3 / 512 / 22e-9));*/ /* set refresh time interval */
  199.   outWarp(REFC_REG,0x00000002);    /* load local refresh minimum */
  200.   outWarp(REFD_REG,0x00000008);    /* load local refresh maximum */
  201.   outWarp(REFE_REG,0x00000008);    /* load host refresh minimum */
  202.   outWarp(REFF_REG,0x00000020);    /* load host refresh max */
  203.  
  204.   outWarp(MASK_B_REG, 0x00000000);
  205.   outWarp(DISABLE_REG,  0xffffffff);  /* 0x00000000 */
  206.   outWarp(PATTERN_RAM,  0x00000000);  /* clear the pattern ram */
  207.   outWarp(PATTERN_RAM1, 0x00000000);
  208.   outWarp(PATTERN_RAM2, 0x00000000);
  209.   outWarp(PATTERN_RAM3, 0x00000000);
  210.   outWarp(PATTERN_RAM4, 0x00000000);
  211.   outWarp(PATTERN_RAM5, 0x00000000);
  212.   outWarp(PATTERN_RAM6, 0x00000000);
  213.   outWarp(PATTERN_RAM7, 0x00000000);
  214.  
  215. #ifdef BLAH
  216.   outWarp(MASK_REG,0xffbfffff);
  217.   outWarp(STATUS_REG,0x08000000);
  218.   outWarp(STATUS_REG,0x0);
  219.   outWarp(MASK_REG,0xffdfffff);
  220.   outWarp(REF0_REG,0x61000000);       /* rfrsh dram & vram, en scrn rfrs */   
  221.   outWarp(REF1_REG,0x00000000);
  222.  
  223.   outWarp(MASK_REG,0x00000000);       /* open everything up to be modified */
  224.   outWarp(STATUS_REG,0);              /* start 'er up */
  225.  
  226.   outWarp(MASK_B_REG,0x003fffff);     /* open everything up (except rsvd) */
  227. #endif
  228.  
  229.   outWarp(CONTROL_REG,0x180c0c40);    /* 0x18020c42 */ /* start 'er up */  
  230.   outWarp(STATUS_REG,0x00009100);       /* int on Idle & vsync */
  231. /*  outWarp(STATUS_REG,0x00008100); */      /* int on Idle only */ 
  232.   outWarp(C_AND_A_REG,0xffff0000);
  233.   outWarp(OFFSET_REG  ,0x00000100);   /* 0x00 */ /* offset for alpha blending */
  234.   outWarp(BNDH_REG    ,0xff);         /* color masking or saturation high */
  235.   outWarp(BNDL_REG    ,0x0);          /* color masking or saturation low */
  236.   outWarp(PMASK_REG   ,0x0);          /* plane mask register */
  237.   outWarp(DASH_REG    ,0x0);          /* pat color or alpha */
  238.   outWarp(DISABLE_REG ,0x0);          /* pat color or alpha */
  239.   outWarp(HOST_PITCH_REG,4096); /* 0x00000400);*/ /* num to inc with inc in y when bltng */
  240.  
  241.  
  242.   outWarp(BANK_ENABLE_REG, 0x00000000);  /* enable all 6 memory banks */
  243.   outWarp(BANK_MASK_REG,   0x00000008);  /* 0x00000000 */ /* why 8 ?? */
  244.   outWarp(BANK_COMPARE_REG,0x00008888);  /* 0x88888888 */ /* ?? */
  245.  
  246.   outWarp(MASK_REG,0xffffffff);       /* lock everything back up */
  247.   outWarp(MASK_B_REG,0xf7ffffff);     /*  "        "      "    " */
  248.  
  249.   /* find the second meg of host memory */
  250.   for(i=4; i<17; i++)
  251.   {
  252.     t=(BYTE*)(clgd547xLogicalBase + i*0x40000);
  253.     *((unsigned int *)clgd547xLogicalBase)=0xa5a5a5a5;
  254.     
  255.     *((unsigned int *)t)=0x12345678;
  256.     *((unsigned int *)(t+8))=0xfedcba98;
  257.     if ((*((unsigned int *)clgd547xLogicalBase)==0xa5a5a5a5) &&
  258.         (*((unsigned int *)t)==0x12345678) &&
  259.         (*((unsigned int *)(t+8))==0xfedcba98)) {
  260.       clgd547xLogicalBase2=(char*)t;
  261.       clgd5470LogicalBase2=(unsigned int*)t;
  262.       break;
  263.     }
  264.   }       
  265.  
  266. #ifdef BLAH
  267.   printf("clgd5470Init()-testing first megabyte of host memory\n");
  268.   printf("clgd5470Init()-%d errors\n",clgd547xTestMegabyte(clgd5470LogicalBase));
  269.   printf("clgd5470Init()-testing second megabyte of host memory\n");
  270.   printf("clgd5470Init()-%d errors\n",clgd547xTestMegabyte(clgd5470LogicalBase2));
  271.   
  272.   /* test again */
  273.   printf("clgd5470Init()-testing both banks again\n");
  274.   for(i=0;i<1024*1024/4;i++) {
  275.     clgd5470LogicalBase[i]=i;
  276.   }
  277.   for(i=0;i<1024*1024/4;i++) {
  278.     clgd5470LogicalBase2[i]=i+262144;
  279.   }
  280.   for(i=0;i<1024*1024/4;i++) {
  281.     if(clgd5470LogicalBase[i]!=i)
  282.       printf("clgd5470LogicalBase, location %d failed\n",i);
  283.   }
  284.   for(i=0;i<1024*1024/4;i++) {
  285.     if(clgd5470LogicalBase2[i]!=(i+262144))
  286.       printf("clgd5470LogicalBase2, location %d failed\n",i);
  287.   }   
  288. #endif
  289.    
  290.   /* test warp execution engine */
  291.   printf("clgd5470Init() - testing 5470 execution engine\n");
  292.   
  293.   listPtr=clgd5470LogicalBase;
  294.   
  295.   for(i=0;i<40;i++) {
  296.     *listPtr++=load_long_ro(PATTERN_RAM,1);
  297.     *listPtr++=0xffffffff;
  298.   }
  299.   *listPtr=IDLE;
  300.   
  301.   outWarp(HOST_INSTRUCTION_REG,branch_ro(0x00));
  302.   
  303.   i=1000000;
  304.   iopl(3);
  305.   outb(0x3ce,0x3a);
  306.   while((inb(0x3cf) & 0x02) && i--);
  307.   iopl(0);
  308.   
  309.   status=inWarp(STATUS_REG);
  310.   
  311.   if (i==0) {
  312.     printf("clgd5470Init() - 5470 execution engine not responding\n");
  313.     return;
  314.   }
  315.   else {
  316.     printf("clgd5470Init() - 5470 execution engine okay\n");
  317.   }
  318.  
  319.   listPtr=clgd5470LogicalBase;  
  320.   *listPtr++=load_short_ro(BANK_MASK_REG, BLUE_BANK);
  321.   *listPtr++=load_long_ro(C_AND_A_REG,1);
  322.   *listPtr++=0xffff0000;
  323.   *listPtr++=blit_ro(BLTFZ, PRAMPAT+PATA_PATB+PRAMALF,A_ONLY);
  324.   *listPtr++=0x03000000;
  325.   *listPtr++=0xff001000;
  326.   *listPtr++=0x00000000; 
  327.   *listPtr++=0x003ff000;
  328.   
  329.   *listPtr++=load_short_ro(BANK_MASK_REG, GREEN_BANK | RED_BANK);
  330.   *listPtr++=load_long_ro(C_AND_A_REG,1);
  331.   *listPtr++=0xffff0000;
  332.   *listPtr++=blit_ro(BLTFZ, PRAMPAT+PATA_PATB+PRAMALF, A_ONLY);
  333.   *listPtr++=0x03000000;
  334.   *listPtr++=0xff001000;
  335.   *listPtr++=0x00000000;
  336.   *listPtr++=0x003ff000;
  337.   
  338.   *listPtr++=IDLE;
  339.   *listPtr++=IDLE;
  340.   *listPtr++=IDLE;
  341.   
  342.   outWarp(HOST_INSTRUCTION_REG, branch_ro(0x00000));
  343.   i=0x1000000;
  344.  
  345.   iopl(3);
  346.   outb(0x3ce,0x3a);
  347.   while((inb(0x3cf) & 0x02) && i--);
  348.   iopl(0);
  349.  
  350.   listPtr0 = clgd5470LogicalBase;
  351.   listMax0 = listPtr0 + 0x00080000/4 - MAXINSTR;
  352.   listPtr1 = clgd5470LogicalBase + 0x00080000/4;
  353.   listMax1 = listPtr1 + 0x00080000/4 - MAXINSTR;
  354.   
  355.   listNum = 0;
  356.   listPtr = listPtr0;
  357.   listMax = listMax0;
  358.   
  359.   printf("init5470: leaving\n");
  360.  
  361. }
  362.  
  363.