savage_vid.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,412 行 · 第 1/3 页

C
1,412
字号
    debugout(SSTREAM_WINDOW_SIZE_REG, OS_WH(info->drw_w, info->drw_h) );    ssControl = 0;    if( info->src_w > (info->drw_w << 1) )    {	/* BUGBUG shouldn't this be >=?  */	if( info->src_w <= (info->drw_w << 2) )	    ssControl |= HDSCALE_4;	else if( info->src_w > (info->drw_w << 3) )	    ssControl |= HDSCALE_8;	else if( info->src_w > (info->drw_w << 4) )	    ssControl |= HDSCALE_16;	else if( info->src_w > (info->drw_w << 5) )	    ssControl |= HDSCALE_32;	else if( info->src_w > (info->drw_w << 6) )	    ssControl |= HDSCALE_64;    }    ssControl |= info->src_w;    ssControl |= (1 << 24);    //FIXME: enable scaling    OUTREG(SSTREAM_CONTROL_REG, ssControl);    debugout(SSTREAM_CONTROL_REG, ssControl);		// FIXME: this should actually be enabled		    info->pitch = (info->pitch + 7) / 8;    VGAOUT8(vgaCRIndex, 0x92);    cr92 = VGAIN8(vgaCRReg);    VGAOUT8(vgaCRReg, (cr92 & 0x40) | (info->pitch >> 8) | 0x80);    VGAOUT8(vgaCRIndex, 0x93);    VGAOUT8(vgaCRReg, info->pitch);    OUTREG(STREAMS_FIFO_REG, 2 | 25 << 5 | 32 << 11);		        }static void SavageInitStreamsOld(void){    /*unsigned long jDelta;*/    unsigned long format = 0;    /*     * For the OLD streams engine, several of these registers     * cannot be touched unless streams are on.  Seems backwards to me;     * I'd want to set 'em up, then cut 'em loose.     */	/*jDelta = pScrn->displayWidth * (pScrn->bitsPerPixel + 7) / 8;*/	switch( info->depth ) {	    case  8: format = 0 << 24; break;	    case 15: format = 3 << 24; break;	    case 16: format = 5 << 24; break;	    case 24: format = 7 << 24; break;	}#warning enable this again	OUTREG(PSTREAM_FBSIZE_REG, 		info->screen_y * info->screen_x * (info->bpp >> 3));        OUTREG( PSTREAM_WINDOW_START_REG, OS_XY(0,0) );    OUTREG( PSTREAM_WINDOW_SIZE_REG, OS_WH(info->screen_x, info->screen_y) );    OUTREG( PSTREAM_FBADDR1_REG, 0 );     /*OUTREG( PSTREAM_STRIDE_REG, jDelta );*/    OUTREG( PSTREAM_CONTROL_REG, format );    OUTREG( PSTREAM_FBADDR0_REG, 0 );		    /*OUTREG( PSTREAM_FBSIZE_REG, jDelta * pScrn->virtualY >> 3 );*/    OUTREG( COL_CHROMA_KEY_CONTROL_REG, 0 );    OUTREG( SSTREAM_CONTROL_REG, 0 );    OUTREG( CHROMA_KEY_UPPER_BOUND_REG, 0 );    OUTREG( SSTREAM_STRETCH_REG, 0 );    OUTREG( COLOR_ADJUSTMENT_REG, 0 );    OUTREG( BLEND_CONTROL_REG, 1 << 24 );    OUTREG( DOUBLE_BUFFER_REG, 0 );    OUTREG( SSTREAM_FBADDR0_REG, 0 );    OUTREG( SSTREAM_FBADDR1_REG, 0 );    OUTREG( SSTREAM_FBADDR2_REG, 0 );    OUTREG( SSTREAM_FBSIZE_REG, 0 );    OUTREG( SSTREAM_STRIDE_REG, 0 );    OUTREG( SSTREAM_VSCALE_REG, 0 );    OUTREG( SSTREAM_LINES_REG, 0 );    OUTREG( SSTREAM_VINITIAL_REG, 0 );#warning is this needed?    OUTREG( SSTREAM_WINDOW_START_REG, OS_XY(0xfffe, 0xfffe) );    OUTREG( SSTREAM_WINDOW_SIZE_REG, OS_WH(10,2) );}static void SavageStreamsOn(void){     unsigned char jStreamsControl;     unsigned short vgaCRIndex = 0x3d0 + 4;     unsigned short vgaCRReg = 0x3d0 + 5;//    xf86ErrorFVerb(STREAMS_TRACE, "SavageStreamsOn\n" );    /* Sequence stolen from streams.c in M7 NT driver */		enable_app_io ();    /* Unlock extended registers. */	/* FIXME: it looks like mmaped io is broken with vgaout16  */    VGAOUT16(vgaCRIndex, 0x4838 );    VGAOUT16(vgaCRIndex, 0xa039);    VGAOUT16(0x3c4, 0x0608);			    VGAOUT8( vgaCRIndex, EXT_MISC_CTRL2 );    if( S3_SAVAGE_MOBILE_SERIES(info->chip.arch) )    {//	SavageInitStreamsNew( pScrn );	jStreamsControl = VGAIN8( vgaCRReg ) | ENABLE_STREAM1;	    /* Wait for VBLANK. */		    VerticalRetraceWait();	    /* Fire up streams! */	    VGAOUT16( vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2 );	/* These values specify brightness, contrast, saturation and hue. */	    OUTREG( SEC_STREAM_COLOR_CONVERT1, 0x0000C892 );	    OUTREG( SEC_STREAM_COLOR_CONVERT2, 0x00039F9A );	    OUTREG( SEC_STREAM_COLOR_CONVERT3, 0x01F1547E );    }    else if (info->chip.arch == S3_SAVAGE2000)    {//	SavageInitStreams2000( pScrn );	jStreamsControl = VGAIN8( vgaCRReg ) | ENABLE_STREAM1;	/* Wait for VBLANK. */		VerticalRetraceWait();	/* Fire up streams! */	VGAOUT16( vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2 );	/* These values specify brightness, contrast, saturation and hue. */	OUTREG( SEC_STREAM_COLOR_CONVERT0_2000, 0x0000C892 );	OUTREG( SEC_STREAM_COLOR_CONVERT1_2000, 0x00033400 );	OUTREG( SEC_STREAM_COLOR_CONVERT2_2000, 0x000001CF );	OUTREG( SEC_STREAM_COLOR_CONVERT3_2000, 0x01F1547E );    }    else    {	jStreamsControl = VGAIN8( vgaCRReg ) | ENABLE_STREAMS_OLD;	/* Wait for VBLANK. */		VerticalRetraceWait();	/* Fire up streams! */	VGAOUT16( vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2 );	SavageInitStreamsOld( );    }    /* Wait for VBLANK. */        VerticalRetraceWait();    /* Turn on secondary stream TV flicker filter, once we support TV. */    /* SR70 |= 0x10 */    info->videoFlags |= VF_STREAMS_ON;}static void savage_getscreenproperties(struct savage_info *info){  unsigned char bpp=0;  uint32_t vgaIOBase, vgaCRIndex, vgaCRReg;  vgaIOBase = 0x3d0;  vgaCRIndex = vgaIOBase + 4;  vgaCRReg = vgaIOBase + 5;  /* a little reversed from x driver source code */  VGAOUT8(vgaCRIndex, 0x67);  bpp = VGAIN8(vgaCRReg);  switch (bpp&0xf0) {  case 0x00:  case 0x10:      info->depth=8;      info->bpp=8;      break;  case 0x20:  case 0x30:      info->depth=15;      info->bpp=16;      break;  case 0x40:  case 0x50:      info->depth=16;      info->bpp=16;      break;  case 0x70:  case 0xd0:      info->depth=24;      info->bpp=32;      break;  }  VGAOUT8(vgaCRIndex, 0x1);  info->screen_x = (1 + VGAIN8(vgaCRReg))  <<3;  /*get screen height*/  /* get first 8 bits in VT_DISPLAY_END*/  VGAOUT8(0x03D4, 0x12);  info->screen_y = VGAIN8(0x03D5);  VGAOUT8(0x03D4,0x07);  /* get 9th bit in CRTC_OVERFLOW*/  info->screen_y |= (VGAIN8(0x03D5) &0x02)<<7;  /* and the 10th in CRTC_OVERFLOW*/  info->screen_y |=(VGAIN8(0x03D5) &0x40)<<3;  ++info->screen_y;	printf("screen_x = %d, screen_y = %d, bpp = %d\n",info->screen_x,info->screen_y,info->bpp);}static void SavageStreamsOff(void){    unsigned char jStreamsControl;    unsigned short vgaCRIndex = 0x3d0 + 4;    unsigned short vgaCRReg = 0x3d0 + 5;    /* Unlock extended registers. */    VGAOUT16(vgaCRIndex, 0x4838);    VGAOUT16(vgaCRIndex, 0xa039);    VGAOUT16(0x3c4, 0x0608);    VGAOUT8( vgaCRIndex, EXT_MISC_CTRL2 );    if( S3_SAVAGE_MOBILE_SERIES(info->chip.arch)  ||        (info->chip.arch == S3_SUPERSAVAGE) ||        (info->chip.arch == S3_SAVAGE2000) )	jStreamsControl = VGAIN8( vgaCRReg ) & NO_STREAMS;    else	jStreamsControl = VGAIN8( vgaCRReg ) & NO_STREAMS_OLD;    /* Wait for VBLANK. */    VerticalRetraceWait();    /* Kill streams. */    VGAOUT16(vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2 );    VGAOUT16(vgaCRIndex, 0x0093 );    VGAOUT8( vgaCRIndex, 0x92 );    VGAOUT8( vgaCRReg, VGAIN8(vgaCRReg) & 0x40 );    info->videoFlags &= ~VF_STREAMS_ON;}/** * @brief Find chip index in Unichrome compliant devices list. * * @param chip_id PCI device ID. * * @returns index position in savage_card_ids if successful. *          -1 if chip_id is not a compliant chipset ID. */static int find_chip(unsigned chip_id){  unsigned i;  for(i = 0;i < sizeof(savage_card_ids)/sizeof(struct savage_cards);i++)  {    if(chip_id == savage_card_ids[i].chip_id)return i;  }  return -1;}/** * @brief Probe hardware to find some useable chipset. * * @param verbose specifies verbose level. * @param force specifies force mode : driver should ignore *              device_id (danger but useful for new devices) * * @returns 0 if it can handle something in PC. *          a negative error code otherwise. */static int savage_probe(int verbose, int force){    pciinfo_t lst[MAX_PCI_DEVICES];    unsigned i,num_pci;    int err;    if (force)	    printf("[savage_vid]: warning: forcing not supported yet!\n");    err = pci_scan(lst,&num_pci);    if(err){	printf("[savage_vid] Error occurred during pci scan: %s\n",strerror(err));	return err;    }    else {	err = ENXIO;	for(i=0; i < num_pci; i++){	    if(lst[i].vendor == VENDOR_S3_INC) {		int idx;		const char *dname;		idx = find_chip(lst[i].device);		if(idx == -1)		    continue;		dname = pci_device_name(lst[i].vendor, lst[i].device);		dname = dname ? dname : "Unknown chip";		printf("[savage_vid] Found chip: %s\n", dname);		// FIXME: whats wrong here?		if ((lst[i].command & PCI_COMMAND_IO ) == 0){			printf("[savage_vid] Device is disabled, ignoring\n");			continue;		}		savage_cap.device_id = lst[i].device;		err = 0;		memcpy(&pci_info, &lst[i], sizeof(pciinfo_t));		break;	    }	}    }    if(err && verbose) printf("[savage_vid] Can't find chip\n");    return err;}/** * @brief Initializes driver. * * @returns 0 if ok. *          a negative error code otherwise. */static intsavage_init (void){	int mtrr;  unsigned char config1, tmp;  static unsigned char RamSavage3D[] = { 8, 4, 4, 2 };  static unsigned char RamSavage4[] =  { 2, 4, 8, 12, 16, 32, 64, 32 };  static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 };  static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 16, 2 };  int videoRam;  uint32_t   vgaIOBase, vgaCRIndex, vgaCRReg ;  unsigned char val;  vgaIOBase = 0x3d0;  vgaCRIndex = vgaIOBase + 4;  vgaCRReg = vgaIOBase + 5;	fprintf(stderr, "vixInit enter \n");//	//getc(stdin);	  info = calloc(1,sizeof(savage_info));    /* need this if we want direct outb and inb access? */  enable_app_io ();  /* 12mb + 32kb ? */  /* allocate some space for control registers */  info->chip.arch =  savage_card_ids[find_chip(pci_info.device)].arch;    if (info->chip.arch == S3_SAVAGE3D) {      info->control_base = map_phys_mem(pci_info.base0+SAVAGE_NEWMMIO_REGBASE_S3, SAVAGE_NEWMMIO_REGSIZE);  }  else {      info->control_base = map_phys_mem(pci_info.base0+SAVAGE_NEWMMIO_REGBASE_S4, SAVAGE_NEWMMIO_REGSIZE);  }//  info->chip.PCIO   = (uint8_t *)  (info->control_base + SAVAGE_NEWMMIO_VGABASE);  // FIXME: enable mmio?  val = VGAIN8 (0x3c3);  VGAOUT8 (0x3c3, val | 0x01);  val = VGAIN8 (0x3cc);  VGAOUT8 (0x3c2, val | 0x01);  if (info->chip.arch >= S3_SAVAGE4)	{		VGAOUT8 (0x3d4, 0x40);		val = VGAIN8 (0x3d5);		VGAOUT8 (0x3d5, val | 1);	}  /* unprotect CRTC[0-7] */  VGAOUT8(vgaCRIndex, 0x11);  tmp = VGAIN8(vgaCRReg);//  printf("$########## tmp = %d\n",tmp);  VGAOUT8(vgaCRReg, tmp & 0x7f);  /* unlock extended regs */  VGAOUT16(vgaCRIndex, 0x4838);  VGAOUT16(vgaCRIndex, 0xa039);  VGAOUT16(0x3c4, 0x0608);  VGAOUT8(vgaCRIndex, 0x40);  tmp = VGAIN8(vgaCRReg);  VGAOUT8(vgaCRReg, tmp & ~0x01);  /* unlock sys regs */  VGAOUT8(vgaCRIndex, 0x38);  VGAOUT8(vgaCRReg, 0x48);  /* Unlock system registers. */  VGAOUT16(vgaCRIndex, 0x4838);  /* Next go on to detect amount of installed ram */  VGAOUT8(vgaCRIndex, 0x36);            /* for register CR36 (CONFG_REG1), */  config1 = VGAIN8(vgaCRReg);           /* get amount of vram installed */  switch( info->chip.arch ) {    case S3_SAVAGE3D:      videoRam = RamSavage3D[ (config1 & 0xC0) >> 6 ] * 1024;      break;    case S3_SAVAGE4:		/* 			* The Savage4 has one ugly special case to consider.  On			* systems with 4 banks of 2Mx32 SDRAM, the BIOS says 4MB			* when it really means 8MB.  Why do it the same when you			* can do it different...			*/			VGAOUT8(0x3d4, 0x68);  /* memory control 1 */			if( (VGAIN8(0x3d5) & 0xC0) == (0x01 << 6) )				RamSavage4[1] = 8;			/*FALLTHROUGH*/		case S3_SAVAGE2000:			videoRam = RamSavage4[ (config1 & 0xE0) >> 5 ] * 1024;			break;		case S3_SAVAGE_MX:			videoRam = RamSavageMX[ (config1 & 0x0E) >> 1 ] * 1024;			break;		case S3_PROSAVAGE:			videoRam = RamSavageNB[ (config1 & 0xE0) >> 5 ] * 1024;			break;		default:			/* How did we get here? */			videoRam = 0;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?