#include <stdlib.h>
#include <linux/pci.h>
#include <asm/types.h>
#include <asm/io.h>
#include "endianess.h"
#include "libvga.h"
#include "svgalib_helper.h"
#include "interrupt.h"
static struct sh_pci_device graph_dev
;
static struct pci_dev dev
;
DWORD __svgalib_pci_read_config_dword
(int pos
, int address
);
int init_vgapci
(void)
{
int i
;
DWORD result
;
BYTE bus
,dv
;
printk
(KERN_INFO
"Initializing PCI BUS...\n");
memset(&graph_dev
,0,sizeof(struct pci_dev
));
/* Scan the devices connected to the PCI bus */
if (pci_init
() != 1) return -1;
if(pci_present
()) {
pci_class
(PCI_CLASS_DISPLAY_VGA
<<8,0,&bus
,&dv
);
dev.
bus->number
= bus
;
dev.
devfn = dv
;
memcpy(&(graph_dev.
dev),&dev
,sizeof(struct pci_dev
));
pci_read_config_word
(&dev
,0,&(graph_dev.
vendor));
pci_read_config_word
(&dev
,2,&(graph_dev.
id));
pci_read_config_byte
(&dev
,8,&(graph_dev.
revision));
printk
(KERN_INFO
"VGA Vendor:%.4x id:%.4x bus:%d dev:%d\n",\
graph_dev.
vendor,graph_dev.
id,bus
,dv
);
for(i
=0;i
<6;i
++){
DWORD t
;
int len
;
pci_read_config_dword
(&dev
,16+4*i
,&result
);
if(result
) {
pci_write_config_dword
(&dev
,16+4*i
,0xffffffff);
pci_read_config_dword
(&dev
,16+4*i
,&t
);
pci_write_config_dword
(&dev
,16+4*i
,result
);
len
= ~
(t
&~
0xf)+1;
if (len
){
graph_dev.
mem[i
]=result
&~
0xf;
graph_dev.
flags[i
]=0x80 | (result
&0xf);
graph_dev.
len[i
]=len
;
graph_dev.
mask[i
]=t
&~
0xf;
printk
(KERN_INFO
"region%d, base=%.8lx len=%d type=%ld\n",\
i
, result
&(~
0xf), len
, result
&0xf);
}
}
}
vga_init_vsync
(&graph_dev
);
}
return 0;
}
static int proc_pci_read_config
(DWORD
*buf
, int size
)
{
int i
;
for(i
=0;i
<size
;i
++) {
buf
[i
]=__svgalib_pci_read_config_dword
(0,i
*4);
}
return 0;
};
/*
find a vga device of the specified vendor, and return
its configuration (64 dwords) in conf
return zero if device found.
*/
int __svgalib_pci_find_vendor_vga
(unsigned int vendor
, unsigned long *conf
, int cont
)
{
DWORD buf
[64];
proc_pci_read_config
(buf
,64);
if(((buf
[0]&0xffff)==vendor
)&&
(((buf
[2]>>16)&0xffff)==0x0300)) { /* VGA Class */
memcpy(conf
,buf
,256);
return 0;
}
return 1;
}
unsigned char __svgalib_pci_read_config_byte
(int pos
, int address
)
{
u8 t
;
pci_read_config_byte
(&dev
, (BYTE
)address
, &t
);
return t
;
};
unsigned int __svgalib_pci_read_config_word
(int pos
, int address
)
{
u16 t
;
pci_read_config_word
(&dev
, (BYTE
)address
, &t
);
return t
;
};
DWORD __svgalib_pci_read_config_dword
(int pos
, int address
)
{
DWORD t
;
pci_read_config_dword
(&dev
, (BYTE
)address
, &t
);
return t
;
};
int __svgalib_pci_read_aperture_len
(int pos
, int address
)
{
return graph_dev.
len[address
];
};
void __svgalib_pci_write_config_byte
(int pos
, int address
, unsigned char data
)
{
pci_write_config_byte
(&dev
, (BYTE
)address
, data
);
};
void __svgalib_pci_write_config_word
(int pos
, int address
, unsigned int data
)
{
pci_write_config_word
(&dev
, (BYTE
)address
, data
);
};
void __svgalib_pci_write_config_dword
(int pos
, int address
, DWORD data
)
{
pci_write_config_dword
(&dev
, (BYTE
)address
, data
);
};