Subversion Repositories shark

Rev

Rev 184 | Rev 189 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
54 pj 1
#include <stdlib.h>
2
#include <linux/pci.h>
3
 
4
#include <asm/types.h>
5
#include <asm/io.h>
6
 
7
#include "endianess.h"
8
#include "libvga.h"
9
#include "svgalib_helper.h"
10
#include "interrupt.h"
11
 
12
static struct sh_pci_device graph_dev;
13
static struct pci_dev dev;
14
 
15
DWORD __svgalib_pci_read_config_dword(int pos, int address);
16
 
17
int init_vgapci(void)
18
{
19
    int i;
185 giacomo 20
    DWORD result,dw;
54 pj 21
    BYTE bus,dv;
22
 
184 giacomo 23
    printk(KERN_INFO "Initializing PCI BUS...\n");
54 pj 24
 
25
    memset(&graph_dev,0,sizeof(struct pci_dev));
26
 
27
    /* Scan the devices connected to the PCI bus */
184 giacomo 28
    if (pci_init() != 1) return -1;
54 pj 29
 
30
    if(pci_present()) {
31
 
32
            pci_class(PCI_CLASS_DISPLAY_VGA<<8,0,&bus,&dv);
33
 
34
            dev.bus->number = bus;
35
            dev.devfn = dv;
36
            memcpy(&(graph_dev.dev),&dev,sizeof(struct pci_dev));
37
 
38
            pci_read_config_word(&dev,0,&(graph_dev.vendor));
39
            pci_read_config_word(&dev,2,&(graph_dev.id));
40
            pci_read_config_byte(&dev,8,&(graph_dev.revision));
41
            printk(KERN_INFO "VGA Vendor:%.4x id:%.4x bus:%d dev:%d\n",\
42
                graph_dev.vendor,graph_dev.id,bus,dv);
43
            for(i=0;i<6;i++){
44
                DWORD t;
45
                int len;
46
                pci_read_config_dword(&dev,16+4*i,&result);
47
                if(result) {
48
                    pci_write_config_dword(&dev,16+4*i,0xffffffff);
49
                    pci_read_config_dword(&dev,16+4*i,&t);
50
                    pci_write_config_dword(&dev,16+4*i,result);
51
                    len = ~(t&~0xf)+1;
52
                    if (len){
53
                       graph_dev.mem[i]=result&~0xf;
54
                       graph_dev.flags[i]=0x80 | (result&0xf);
55
                       graph_dev.len[i]=len;
56
                       graph_dev.mask[i]=t&~0xf;
184 giacomo 57
                       printk(KERN_INFO "region%d, base=%.8lx len=%d type=%ld\n",\
54 pj 58
                        i, result&(~0xf), len, result&0xf);
59
                    }
60
                }
61
            }
185 giacomo 62
 
63
            pcibios_read_config_dword(bus,dv,PCI_COMMAND,&dw);
64
            dw |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
65
            pcibios_write_config_dword(bus,dv,PCI_COMMAND,dw);
54 pj 66
 
184 giacomo 67
            //vga_init_vsync(&graph_dev);
54 pj 68
 
69
    }
70
 
71
    return 0;
72
 
73
}
74
 
75
static int proc_pci_read_config(DWORD *buf, int size)
76
{
77
   int i;
78
 
79
   for(i=0;i<size;i++) {
80
       buf[i]=__svgalib_pci_read_config_dword(0,i*4);
81
   }
82
 
83
   return 0;
84
 
85
};
86
 
87
/*
88
   find a vga device of the specified vendor, and return
89
   its configuration (64 dwords) in conf
90
   return zero if device found.
91
*/
92
 
93
int __svgalib_pci_find_vendor_vga(unsigned int vendor, unsigned long *conf, int cont)
94
{
95
  DWORD buf[64];
96
 
97
  proc_pci_read_config(buf,64);
98
 
99
  if(((buf[0]&0xffff)==vendor)&&
100
    (((buf[2]>>16)&0xffff)==0x0300)) { /* VGA Class */
101
       memcpy(conf,buf,256);
102
       return 0;
103
    }  
104
 
105
  return 1;
106
 
107
}
108
 
109
unsigned char __svgalib_pci_read_config_byte(int pos, int address)
110
{
111
    u8 t;
112
 
113
    pci_read_config_byte(&dev, (BYTE)address, &t);     
114
 
115
    return t;
116
 
117
};
118
 
119
unsigned int __svgalib_pci_read_config_word(int pos, int address)
120
{
121
 
122
    u16 t;
123
 
124
    pci_read_config_word(&dev, (BYTE)address, &t);
125
 
126
    return t;
127
 
128
};
129
 
130
DWORD __svgalib_pci_read_config_dword(int pos, int address)
131
{
132
    DWORD t;
133
 
134
    pci_read_config_dword(&dev, (BYTE)address, &t);
135
 
136
    return t;
137
 
138
};
139
 
140
int __svgalib_pci_read_aperture_len(int pos, int address)
141
{
142
 
143
    return graph_dev.len[address];
144
 
145
};
146
 
147
void __svgalib_pci_write_config_byte(int pos, int address, unsigned char data)
148
{
149
 
150
    pci_write_config_byte(&dev, (BYTE)address, data);
151
 
152
};
153
 
154
void __svgalib_pci_write_config_word(int pos, int address, unsigned int data)
155
{
156
 
157
    pci_write_config_word(&dev, (BYTE)address, data);
158
 
159
};
160
 
161
void __svgalib_pci_write_config_dword(int pos, int address, DWORD data)
162
{
163
 
164
    pci_write_config_dword(&dev, (BYTE)address, data);
165
 
166
};
167