Example #1
0
static pointer
mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
{
	pointer base;
	int fd;

#if defined(SVR4)
	fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
	if (fd < 0)
	{
		FatalError("xf86MapVidMem: failed to open %s (%s)\n",
			   DEV_MEM, strerror(errno));
	}
	base = mmap((caddr_t)0, Size,
		    (flags & VIDMEM_READONLY) ?
		     PROT_READ : (PROT_READ | PROT_WRITE),
		    MAP_SHARED, fd, (off_t)Base);
	close(fd);
	if (base == MAP_FAILED)
	{
		FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
			   "xf86MapVidMem", Size, Base, strerror(errno));
	}
#else /* SVR4 */
#ifdef HAS_SVR3_MMAPDRV

	xf86MsgVerb(X_INFO, MMAP_DEBUG, "# xf86MapVidMem: MMAP 2.2.2 called\n");
	xf86MsgVerb(X_INFO, MMAP_DEBUG,
			"MMAP_VERSION: 0x%x\n",ioctl(mmapFd, GETVERSION));
	if (ioctl(mmapFd, GETVERSION) == -1)
	{
		xf86LinearVidMem();
	}
	xf86MsgVerb(X_INFO, MMAP_DEBUG,
			"MMAP_VERSION: 0x%x\n",ioctl(mmapFd, GETVERSION));
	xf86MsgVerb(X_INFO, MMAP_DEBUG,
		"xf86MapVidMem: Screen: %d\n", ScreenNum);
	mmapStat(Base,Size);
	/* To force the MMAP driver to provide the address */
	base = (pointer)0;
	xf86MsgVerb(X_INFO, MMAP_DEBUG,
			"xf86MapVidMem: [s=%x,a=%x]\n", Size, Base);
	MapDSC.vaddr    = (char *)base;
	MapDSC.physaddr = (char *)Base;
	MapDSC.length   = Size;
	MapDSC.ioflg    = 1;
	if(mmapFd >= 0)
	{
	    if((base = (pointer)ioctl(mmapFd, MAP, &MapDSC)) == (pointer)-1)
	    {
		FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
			   "xf86MapVidMem", Size, Base, strerror(errno));
		/* NOTREACHED */
	    }

	    /* Next time we want the same address! */
	    MapDSC.vaddr    = (char *)base;
	}

	xf86MsgVerb(X_INFO, MMAP_DEBUG,
			"MapDSC.vaddr   : 0x%x\n", MapDSC.vaddr);
	xf86MsgVerb(X_INFO, MMAP_DEBUG,
			"MapDSC.physaddr: 0x%x\n", MapDSC.physaddr);
	xf86MsgVerb(X_INFO, MMAP_DEBUG,
			"MapDSC.length  : %d\n", MapDSC.length);
	mmapStat(Base,Size);
	xf86MsgVerb(X_INFO, MMAP_DEBUG,
			"xf86MapVidMem: [s=%x,a=%x,b=%x]\n", Size, Base, base);
	xf86MsgVerb(X_INFO, MMAP_DEBUG,
			"xf86MapVidMem: SUCCEED Mapping FrameBuffer \n");
#endif /* HAS_SVR3_MMAPDRV */
#endif /* SVR4 */
	return base;
}
Example #2
0
_X_EXPORT pointer
xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
{
	pointer base;
	int fd;
	char vtname[20];

	/*
	 * Solaris 2.1 x86 SVR4 (10/27/93)
	 * The server must treat the virtual terminal device file as the
	 * standard SVR4 /dev/pmem.
	 *
	 * Using the /dev/vtXX device as /dev/pmem only works for the
	 * A0000-FFFFF region - If we wish you mmap the linear aperture
	 * it requires a device driver.
	 *
	 * So what we'll do is use /dev/vtXX for the A0000-FFFFF stuff, and
	 * try to use the /dev/fbs/aperture or /dev/xsvc driver if the server
	 * tries to mmap anything > FFFFF.  Its very very unlikely that the
	 * server will try to mmap anything below FFFFF that can't be handled
	 * by /dev/vtXX.
	 *
	 * DWH - 2/23/94
	 * DWH - 1/31/99 (Gee has it really been 5 years?)
	 *
	 * Solaris 2.8 7/26/99
	 * Use /dev/xsvc for everything
	 *
	 * DWH - 7/26/99 - Solaris8/dev/xsvc changes
	 *
	 * TSI - 2001.09 - SPARC changes
	 */

#if defined(i386) && !defined(__SOL8__)
	if(Base < 0xFFFFF)
		sprintf(vtname, "/dev/vt%02d", xf86Info.vtno);
	else
#endif
	{
		if (!xf86LinearVidMem())
			FatalError("xf86MapVidMem:  no aperture device\n");

		strcpy(vtname, apertureDevName);
	}

	fd = open(vtname, (Flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
	if (fd < 0)
		FatalError("xf86MapVidMem: failed to open %s (%s)\n",
			   vtname, strerror(errno));

	base = mmap(NULL, Size,
		    (Flags & VIDMEM_READONLY) ?
			PROT_READ : (PROT_READ | PROT_WRITE),
		     MAP_SHARED, fd, (off_t)Base);
	close(fd);
	if (base == MAP_FAILED)
		FatalError("xf86MapVidMem:  mmap failure:  %s\n",
			   strerror(errno));

	return(base);
}