#include <sys/types.h>
#include <errno.h>
#include <sys/prosrfs.h>
#include <sys/cpu.h>
#include "compiler.h"
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"
volatile unsigned char *ioBase = MAP_FAILED;
unsigned long ioSize = 0;
#undef outb
#undef outw
#undef outl
#undef inb
#undef inw
#undef inl
void
outb(unsigned int a, unsigned char b)
{
if (ioBase == MAP_FAILED) {
ErrorF("outb(0x%04X, 0x%02X) fails. Uninitialized ioBase\n", a, b);
return;
}
*((volatile unsigned char *)(ioBase + a)) = b; eieio();
}
void
outw(unsigned int a, unsigned short w)
{
if (ioBase == MAP_FAILED) {
ErrorF("outw(0x%04X, 0x%04X) fails. Unitialized ioBase\n", a, w);
return;
}
stw_brx(w,ioBase,a); eieio();
}
void
outl(unsigned int a, unsigned int l)
{
if (ioBase == MAP_FAILED) {
ErrorF("outl(0x%04X, 0x%08X) fails. Unitialized ioBase\n", a, l);
return;
}
stl_brx(l,ioBase,a); eieio();
}
unsigned char
inb(unsigned int a)
{
unsigned char b;
if (ioBase == MAP_FAILED) {
FatalError("%s(0x%04X) fails. Unitialized ioBase\n", "inb", a);
}
b = *((volatile unsigned char *)(ioBase + a));
return(b);
}
unsigned short
inw(unsigned int a)
{
unsigned short w;
if (ioBase == MAP_FAILED) {
FatalError("%s(0x%04X) fails. Unitialized ioBase\n", "inw", a);
}
w = ldw_brx(ioBase,a);
return(w);
}
unsigned int
inl(unsigned int a)
{
unsigned int l;
if (ioBase == MAP_FAILED) {
FatalError("%s(0x%04X) fails. Unitialized ioBase\n", "inl", a);
}
l = ldl_brx(ioBase, a);
return(l);
}
#ifdef PPCIO_DEBUG
void
debug_outb(unsigned int a, unsigned char b, int line, char *file)
{
if (xf86Verbose > 3)
ErrorF("outb(0x%04X, 0x%02X) at line %d, file \"%s\"\n", a, b, line, file);
outb(a,b);
}
void
debug_outw(unsigned int a, unsigned short w, int line, char *file)
{
if (xf86Verbose > 3)
ErrorF("outw(0x%04X, 0x%04X) at line %d, file \"%s\"\n", a, w, line, file);
outw(a,w);
}
void
debug_outl(unsigned int a, unsigned int l, int line, char *file)
{
if (xf86Verbose > 3)
ErrorF("outl(0x%04X, 0x%08X) at line %d, file \"%s\"\n", a, l, line, file);
outl(a,l);
}
unsigned char
debug_inb(unsigned int a, int line, char *file)
{
unsigned char b;
if (xf86Verbose > 4)
ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inb", a, line, file);
b = inb(a);
if (xf86Verbose > 3)
ErrorF("... %s(0x%04X) returns 0x%02X\n", "inb", a, b);
return(b);
}
unsigned short
debug_inw(unsigned int a, int line, char *file)
{
unsigned short w;
if (xf86Verbose > 4)
ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inw", a, line, file);
w = inw(a);
if (xf86Verbose > 3)
ErrorF("... %s(0x%04X) returns 0x%04X\n", "inw", a, w);
return(w);
}
unsigned int
debug_inl(unsigned int a, int line, char *file)
{
unsigned int l;
if (xf86Verbose > 4)
ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inl", a, line, file);
l = inl(a);
if (xf86Verbose > 3)
ErrorF("... %s(0x%04X) returns 0x%08X\n", "inl", a, l);
return(l);
}
#endif
#define LINESIZE 32
#define CACHE_LINE(a) (((unsigned long)a) & ~(LINESIZE-1))
void
ppc_flush_icache(char *addr)
{
__inst_dcbf (addr, 0);
__inst_dcbf (addr, LINESIZE);
__inst_sync ();
__inst_icbi (addr, 0);
__inst_icbi (addr, LINESIZE);
__inst_sync ();
__inst_isync ();
}