Commit 9db2af6f authored by Adam Jackson's avatar Adam Jackson 🥃

xfree86: Remove xf86{Map,Unmap}VidMem

This API sucks.  Fortunately it's mostly unused at this point.  geode,
sis, and xgi need minor patches to use the corresponding pciaccess code,
neomagic will (more explicitly) lose its non-PCI support, and newport
will need to be ported to /dev/mem or the platform bus or something.

This should also make it pretty clear that alpha's sparse memory support
was basically not a thing anymore, very few tears shed.
Reviewed-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
Signed-off-by: Adam Jackson's avatarAdam Jackson <ajax@redhat.com>
parent d3427717
This diff is collapsed.
......@@ -66,35 +66,6 @@
#include "xf86_OSlib.h"
#include "xf86OSpriv.h"
#ifdef __arm32__
#include "machine/devmap.h"
struct memAccess {
int ioctl;
struct map_info memInfo;
void *regionVirtBase;
Bool Checked;
Bool OK;
};
static void *xf86MapInfoMap();
static void xf86MapInfoUnmap();
static struct memAccess *checkMapInfo();
extern int vgaPhysLinearBase;
/* A memAccess structure is needed for each possible region */
struct memAccess vgaMemInfo = { CONSOLE_GET_MEM_INFO, NULL, NULL,
FALSE, FALSE
};
struct memAccess linearMemInfo = { CONSOLE_GET_LINEAR_INFO, NULL, NULL,
FALSE, FALSE
};
struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL,
FALSE, FALSE
};
#endif /* __arm32__ */
#if defined(__NetBSD__) && !defined(MAP_FILE)
#define MAP_FLAGS MAP_SHARED
#else
......@@ -111,9 +82,6 @@ struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL,
static Bool useDevMem = FALSE;
static int devMemFd = -1;
static void *mapVidMem(int, unsigned long, unsigned long, int);
static void unmapVidMem(int, void *, unsigned long);
/*
* Check if /dev/mem can be mmap'd. If it can't print a warning when
* "warn" is TRUE.
......@@ -164,57 +132,10 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
checkDevMem(TRUE);
pVidMem->linearSupported = useDevMem;
pVidMem->mapMem = armMapVidMem;
pVidMem->unmapVidMem = armUnmapVidMem;
pVidMem->initialised = TRUE;
}
static void *
mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
{
void *base;
checkDevMem(FALSE);
if (useDevMem) {
if (devMemFd < 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_FLAGS, devMemFd, (off_t) Base + BUS_BASE_BWX);
if (base == MAP_FAILED) {
FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n",
"xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno));
}
return base;
}
/* else, mmap /dev/vga */
if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) {
FatalError("%s: Address 0x%x outside allowable range\n",
"xf86MapVidMem", Base);
}
base = mmap(0, Size,
(flags & VIDMEM_READONLY) ?
PROT_READ : (PROT_READ | PROT_WRITE),
MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base - 0xA0000);
if (base == MAP_FAILED) {
FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
strerror(errno));
}
return base;
}
static void
unmapVidMem(int ScreenNum, void *Base, unsigned long Size)
{
munmap((caddr_t) Base, Size);
}
/*
* Read BIOS via mmap()ing DEV_MEM
*/
......@@ -258,162 +179,6 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
return Len;
}
/* XXX This needs to be updated for the ND */
/*
** Find out whether the console driver provides memory mapping information
** for the specified region and return the map_info pointer. Print a warning if required.
*/
static struct memAccess *
checkMapInfo(Bool warn, int Region)
{
struct memAccess *memAccP;
switch (Region) {
case VGA_REGION:
memAccP = &vgaMemInfo;
break;
case LINEAR_REGION:
memAccP = &linearMemInfo;
break;
case MMIO_REGION:
memAccP = &ioMemInfo;
break;
default:
return NULL;
break;
}
if (!memAccP->Checked) {
if (ioctl(xf86Info.consoleFd, memAccP->ioctl, &(memAccP->memInfo)) ==
-1) {
if (warn) {
xf86Msg(X_WARNING,
"checkMapInfo: failed to get map info for region %d\n\t(%s)\n",
Region, strerror(errno));
}
}
else {
if (memAccP->memInfo.u.map_info_mmap.map_offset != MAP_INFO_UNKNOWN)
memAccP->OK = TRUE;
}
memAccP->Checked = TRUE;
}
if (memAccP->OK) {
return memAccP;
}
else {
return NULL;
}
}
static void *
xf86MapInfoMap(struct memAccess *memInfoP, void *Base, unsigned long Size)
{
struct map_info *mapInfoP = &(memInfoP->memInfo);
if (mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) {
Size = (unsigned long) Base + Size;
}
else {
Size = mapInfoP->u.map_info_mmap.map_size;
}
switch (mapInfoP->method) {
case MAP_MMAP:
/* Need to remap if size is unknown because we may not have
mapped the whole region initially */
if (memInfoP->regionVirtBase == NULL ||
mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) {
if ((memInfoP->regionVirtBase =
mmap((caddr_t) 0,
Size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
xf86Info.consoleFd,
(unsigned long) mapInfoP->u.map_info_mmap.map_offset))
== (void *) -1) {
FatalError
("xf86MapInfoMap: Failed to map memory at 0x%x\n\t%s\n",
mapInfoP->u.map_info_mmap.map_offset, strerror(errno));
}
if (mapInfoP->u.map_info_mmap.internal_offset > 0)
memInfoP->regionVirtBase +=
mapInfoP->u.map_info_mmap.internal_offset;
}
break;
default:
FatalError("xf86MapInfoMap: Unsuported mapping method\n");
break;
}
return (void *) ((int) memInfoP->regionVirtBase + (int) Base);
}
static void
xf86MapInfoUnmap(struct memAccess *memInfoP, unsigned long Size)
{
struct map_info *mapInfoP = &(memInfoP->memInfo);
switch (mapInfoP->method) {
case MAP_MMAP:
if (memInfoP->regionVirtBase != NULL) {
if (mapInfoP->u.map_info_mmap.map_size != MAP_INFO_UNKNOWN)
Size = mapInfoP->u.map_info_mmap.map_size;
munmap((caddr_t) memInfoP->regionVirtBase, Size);
memInfoP->regionVirtBase = NULL;
}
break;
default:
FatalError("xf86MapInfoMap: Unsuported mapping method\n");
break;
}
}
static void *
armMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
{
struct memAccess *memInfoP;
if ((memInfoP = checkMapInfo(FALSE, Region)) != NULL) {
/*
** xf86 passes in a physical address offset from the start
** of physical memory, but xf86MapInfoMap expects an
** offset from the start of the specified region - it gets
** the physical address of the region from the display driver.
*/
switch (Region) {
case LINEAR_REGION:
if (vgaPhysLinearBase) {
Base -= vgaPhysLinearBase;
}
break;
case VGA_REGION:
Base -= 0xA0000;
break;
}
base = xf86MapInfoMap(memInfoP, Base, Size);
return base;
}
return mapVidMem(ScreenNum, Base, Size, flags);
}
static void
armUnmapVidMem(int ScreenNum, void *Base, unsigned long Size)
{
struct memAccess *memInfoP;
if ((memInfoP = checkMapInfo(FALSE, Region)) != NULL) {
xf86MapInfoUnmap(memInfoP, Base, Size);
}
unmapVidMem(ScreenNum, Base, Size);
}
#ifdef USE_DEV_IO
static int IoFd = -1;
......
......@@ -85,9 +85,6 @@ static int devMemFd = -1;
#define DEV_APERTURE "/dev/xf86"
#endif
static void *mapVidMem(int, unsigned long, unsigned long, int);
static void unmapVidMem(int, void *, unsigned long);
#ifdef HAS_MTRR_SUPPORT
static void *setWC(int, unsigned long, unsigned long, Bool, MessageType);
static void undoWC(int, void *);
......@@ -189,8 +186,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
{
checkDevMem(TRUE);
pVidMem->linearSupported = useDevMem;
pVidMem->mapMem = mapVidMem;
pVidMem->unmapMem = unmapVidMem;
if (useDevMem)
pci_system_init_dev_mem(devMemFd);
......@@ -210,51 +205,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
pVidMem->initialised = TRUE;
}
static void *
mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
{
void *base;
checkDevMem(FALSE);
if (useDevMem) {
if (devMemFd < 0) {
FatalError("xf86MapVidMem: failed to open %s (%s)",
DEV_MEM, strerror(errno));
}
base = mmap((caddr_t) 0, Size,
(flags & VIDMEM_READONLY) ?
PROT_READ : (PROT_READ | PROT_WRITE),
MAP_FLAGS, devMemFd, (off_t) Base);
if (base == MAP_FAILED) {
FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)",
"xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno));
}
return base;
}
/* else, mmap /dev/vga */
if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) {
FatalError("%s: Address 0x%lx outside allowable range",
"xf86MapVidMem", Base);
}
base = mmap(0, Size,
(flags & VIDMEM_READONLY) ?
PROT_READ : (PROT_READ | PROT_WRITE),
MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base - 0xA0000);
if (base == MAP_FAILED) {
FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)",
strerror(errno));
}
return base;
}
static void
unmapVidMem(int ScreenNum, void *Base, unsigned long Size)
{
munmap((caddr_t) Base, Size);
}
/*
* Read BIOS via mmap()ing DEV_MEM
*/
......
......@@ -44,9 +44,6 @@
#define DEV_MEM "/dev/xf86"
#endif
static void *ppcMapVidMem(int, unsigned long, unsigned long, int flags);
static void ppcUnmapVidMem(int, void *, unsigned long);
Bool xf86EnableIO(void);
void xf86DisableIO(void);
......@@ -54,40 +51,12 @@ void
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
{
pVidMem->linearSupported = TRUE;
pVidMem->mapMem = ppcMapVidMem;
pVidMem->unmapMem = ppcUnmapVidMem;
pVidMem->initialised = TRUE;
xf86EnableIO();
}
volatile unsigned char *ioBase = MAP_FAILED;
static void *
ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
{
int fd = xf86Info.consoleFd;
void *base;
#ifdef DEBUG
xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd);
#endif
base = mmap(0, Size,
(flags & VIDMEM_READONLY) ?
PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base);
if (base == MAP_FAILED)
FatalError("%s: could not mmap screen [s=%lx,a=%lx] (%s)",
"xf86MapVidMem", Size, Base, strerror(errno));
return base;
}
static void
ppcUnmapVidMem(int ScreenNum, void *Base, unsigned long Size)
{
munmap(Base, Size);
}
int
xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
int Len)
......
......@@ -38,44 +38,13 @@
/* Video Memory Mapping section */
/***************************************************************************/
static void *sparc64MapVidMem(int, unsigned long, unsigned long, int);
static void sparc64UnmapVidMem(int, void *, unsigned long);
void
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
{
pVidMem->linearSupported = TRUE;
pVidMem->mapMem = sparc64MapVidMem;
pVidMem->unmapMem = sparc64UnmapVidMem;
pVidMem->initialised = TRUE;
}
static void *
sparc64MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size,
int flags)
{
int fd = xf86Info.consoleFd;
void *base;
#ifdef DEBUG
xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd);
#endif
base = mmap(0, Size,
(flags & VIDMEM_READONLY) ?
PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base);
if (base == MAP_FAILED)
FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)",
"xf86MapVidMem", Size, Base, strerror(errno));
return base;
}
static void
sparc64UnmapVidMem(int ScreenNum, void *Base, unsigned long Size)
{
munmap(Base, Size);
}
int
xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
int Len)
......
......@@ -42,68 +42,6 @@
/**************************************************************************
* Video Memory Mapping section
***************************************************************************/
static void *
mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags)
{
mach_port_t device, mem_dev;
memory_object_t mem_obj;
kern_return_t err;
vm_address_t addr = (vm_address_t) 0;
err = get_privileged_ports(NULL, &device);
if (err) {
errno = err;
FatalError("xf86MapVidMem() can't get_privileged_ports. (%s)\n",
strerror(errno));
}
err = device_open(device, D_READ | D_WRITE, "mem", &mem_dev);
mach_port_deallocate(mach_task_self(), device);
if (err) {
errno = err;
FatalError("xf86MapVidMem() can't device_open. (%s)\n",
strerror(errno));
}
err =
device_map(mem_dev, VM_PROT_READ | VM_PROT_WRITE, Base, Size, &mem_obj,
0);
if (err) {
errno = err;
FatalError("xf86MapVidMem() can't device_map. (%s)\n", strerror(errno));
}
err = vm_map(mach_task_self(), &addr, Size, 0, /* mask */
TRUE, /* anywhere */
mem_obj, (vm_offset_t) Base, FALSE, /* copy on write */
VM_PROT_READ | VM_PROT_WRITE,
VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_SHARE);
mach_port_deallocate(mach_task_self(), mem_obj);
if (err) {
errno = err;
FatalError("xf86MapVidMem() can't vm_map.(mem_obj) (%s)\n",
strerror(errno));
}
mach_port_deallocate(mach_task_self(), mem_dev);
if (err) {
errno = err;
FatalError
("xf86MapVidMem() can't mach_port_deallocate.(mem_dev) (%s)\n",
strerror(errno));
}
return (void *) addr;
}
static void
unmapVidMem(int ScreenNum, void *Base, unsigned long Size)
{
kern_return_t err = vm_deallocate(mach_task_self(), (int) Base, Size);
if (err) {
errno = err;
ErrorF("xf86UnMapVidMem: can't dealloc framebuffer space (%s)\n",
strerror(errno));
}
return;
}
/**************************************************************************
* I/O Permissions section
......@@ -147,7 +85,5 @@ void
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
{
pVidMem->linearSupported = TRUE;
pVidMem->mapMem = mapVidMem;
pVidMem->unmapMem = unmapVidMem;
pVidMem->initialised = TRUE;
}
This diff is collapsed.
......@@ -50,14 +50,6 @@
*/
typedef struct {
unsigned long size;
void *virtBase;
void *mtrrInfo;
} MappingRec, *MappingPtr;
typedef struct {
int numMappings;
MappingPtr *mappings;
Bool mtrrEnabled;
MessageType mtrrFrom;
Bool mtrrOptChecked;
......@@ -69,7 +61,7 @@ static int vidMapIndex = -1;
#define VIDMAPPTR(p) ((VidMapPtr)((p)->privates[vidMapIndex].ptr))
static VidMemInfo vidMemInfo = { FALSE, };
static VidMapRec vidMapRec = { 0, NULL, TRUE, X_DEFAULT, FALSE, NULL };
static VidMapRec vidMapRec = { TRUE, X_DEFAULT, FALSE, NULL };
static VidMapPtr
getVidMapRec(int scrnIndex)
......@@ -94,45 +86,6 @@ getVidMapRec(int scrnIndex)
return vp;
}
static MappingPtr
newMapping(VidMapPtr vp)
{
vp->mappings = xnfrealloc(vp->mappings, sizeof(MappingPtr) *
(vp->numMappings + 1));
vp->mappings[vp->numMappings] = xnfcalloc(sizeof(MappingRec), 1);
return vp->mappings[vp->numMappings++];
}
static MappingPtr
findMapping(VidMapPtr vp, void *vbase, unsigned long size)
{
int i;
for (i = 0; i < vp->numMappings; i++) {
if (vp->mappings[i]->virtBase == vbase && vp->mappings[i]->size == size)
return vp->mappings[i];
}
return NULL;
}
static void
removeMapping(VidMapPtr vp, MappingPtr mp)
{
int i, found = 0;
for (i = 0; i < vp->numMappings; i++) {
if (vp->mappings[i] == mp) {
found = 1;
free(vp->mappings[i]);
}
else if (found) {
vp->mappings[i - 1] = vp->mappings[i];
}
}
vp->numMappings--;
vp->mappings[vp->numMappings] = NULL;
}
enum { OPTION_MTRR };
static const OptionInfoRec opts[] = {
......@@ -165,75 +118,6 @@ xf86InitVidMem(void)
}
}
void *
xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
{
void *vbase = NULL;
VidMapPtr vp;
MappingPtr mp;
if (((Flags & VIDMEM_FRAMEBUFFER) &&
(Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT))))
FatalError("Mapping memory with more than one type\n");
xf86InitVidMem();
if (!vidMemInfo.initialised || !vidMemInfo.mapMem)
return NULL;
vbase = vidMemInfo.mapMem(ScreenNum, Base, Size, Flags);
if (!vbase || vbase == (void *) -1)
return NULL;
vp = getVidMapRec(ScreenNum);
mp = newMapping(vp);
mp->size = Size;
mp->virtBase = vbase;
/*
* Check the "mtrr" option even when MTRR isn't supported to avoid
* warnings about unrecognised options.
*/
checkMtrrOption(vp);
if (vp->mtrrEnabled && vidMemInfo.setWC) {
if (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT))
mp->mtrrInfo =
vidMemInfo.setWC(ScreenNum, Base, Size, FALSE, vp->mtrrFrom);
else if (Flags & VIDMEM_FRAMEBUFFER)
mp->mtrrInfo =
vidMemInfo.setWC(ScreenNum, Base, Size, TRUE, vp->mtrrFrom);
}
return vbase;
}
void
xf86UnMapVidMem(int ScreenNum, void *Base, unsigned long Size)
{
VidMapPtr vp;
MappingPtr mp;
if (!vidMemInfo.initialised || !vidMemInfo.unmapMem) {
xf86DrvMsg(ScreenNum, X_WARNING,
"xf86UnMapVidMem() called before xf86MapVidMem()\n");
return;
}
vp = getVidMapRec(ScreenNum);
mp = findMapping(vp, Base, Size);
if (!mp) {
xf86DrvMsg(ScreenNum, X_WARNING,
"xf86UnMapVidMem: cannot find region for [%p,0x%lx]\n",
Base, Size);
return;
}
if (vp->mtrrEnabled && vidMemInfo.undoWC && mp)
vidMemInfo.undoWC(ScreenNum, mp->mtrrInfo);
vidMemInfo.unmapMem(ScreenNum, Base, Size);
removeMapping(vp, mp);
}
Bool
xf86CheckMTRR(int ScreenNum)
{
......
......@@ -107,62 +107,11 @@ solOpenAperture(void)
return TRUE;
}
static void *
solMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags)
{
void *base;
int fd;
int prot;
if (Flags & VIDMEM_READONLY) {
fd = apertureDevFD_ro;
prot = PROT_READ;
}
else {
fd = apertureDevFD_rw;
prot = PROT_READ | PROT_WRITE;
}
if (fd < 0) {
xf86DrvMsg(ScreenNum, X_ERROR,
"solMapVidMem: failed to open %s (%s)\n",
apertureDevName, strerror(errno));
return NULL;
}
base = mmap(NULL, Size, prot, MAP_SHARED, fd, (off_t) Base);
if (base == MAP_FAILED) {
xf86DrvMsg(ScreenNum, X_ERROR,
"solMapVidMem: failed to mmap %s (0x%08lx,0x%lx) (%s)\n",
apertureDevName, Base, Size, strerror(errno));
return NULL;
}
return base;
}
/* ARGSUSED */
static void
solUnMapVidMem(int ScreenNum, void *Base, unsigned long Size)
{
if (munmap(Base, Size) != 0) {
xf86DrvMsgVerb(ScreenNum, X_WARNING, 0,
"solUnMapVidMem: failed to unmap %s"
" (0x%p,0x%lx) (%s)\n",
apertureDevName, Base, Size, strerror(errno));
}
}
_X_HIDDEN void
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
{
pVidMem->linearSupported = solOpenAperture();
if (pVidMem->linearSupported) {
pVidMem->mapMem = solMapVidMem;
pVidMem->unmapMem = solUnMapVidMem;
}
else {
if (!pVidMem->linearSupported) {