Rev 189 | 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; |
||
191 | giacomo | 20 | DWORD result; |
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 | |
189 | giacomo | 63 | vga_init_vsync(&graph_dev); |
54 | pj | 64 | |
65 | } |
||
66 | |||
67 | return 0; |
||
68 | |||
69 | } |
||
70 | |||
71 | static int proc_pci_read_config(DWORD *buf, int size) |
||
72 | { |
||
73 | int i; |
||
74 | |||
75 | for(i=0;i<size;i++) { |
||
76 | buf[i]=__svgalib_pci_read_config_dword(0,i*4); |
||
77 | } |
||
78 | |||
79 | return 0; |
||
80 | |||
81 | }; |
||
82 | |||
83 | /* |
||
84 | find a vga device of the specified vendor, and return |
||
85 | its configuration (64 dwords) in conf |
||
86 | return zero if device found. |
||
87 | */ |
||
88 | |||
89 | int __svgalib_pci_find_vendor_vga(unsigned int vendor, unsigned long *conf, int cont) |
||
90 | { |
||
91 | DWORD buf[64]; |
||
92 | |||
93 | proc_pci_read_config(buf,64); |
||
94 | |||
95 | if(((buf[0]&0xffff)==vendor)&& |
||
96 | (((buf[2]>>16)&0xffff)==0x0300)) { /* VGA Class */ |
||
97 | memcpy(conf,buf,256); |
||
98 | return 0; |
||
99 | } |
||
100 | |||
101 | return 1; |
||
102 | |||
103 | } |
||
104 | |||
105 | unsigned char __svgalib_pci_read_config_byte(int pos, int address) |
||
106 | { |
||
107 | u8 t; |
||
108 | |||
109 | pci_read_config_byte(&dev, (BYTE)address, &t); |
||
110 | |||
111 | return t; |
||
112 | |||
113 | }; |
||
114 | |||
115 | unsigned int __svgalib_pci_read_config_word(int pos, int address) |
||
116 | { |
||
117 | |||
118 | u16 t; |
||
119 | |||
120 | pci_read_config_word(&dev, (BYTE)address, &t); |
||
121 | |||
122 | return t; |
||
123 | |||
124 | }; |
||
125 | |||
126 | DWORD __svgalib_pci_read_config_dword(int pos, int address) |
||
127 | { |
||
128 | DWORD t; |
||
129 | |||
130 | pci_read_config_dword(&dev, (BYTE)address, &t); |
||
131 | |||
132 | return t; |
||
133 | |||
134 | }; |
||
135 | |||
136 | int __svgalib_pci_read_aperture_len(int pos, int address) |
||
137 | { |
||
138 | |||
139 | return graph_dev.len[address]; |
||
140 | |||
141 | }; |
||
142 | |||
143 | void __svgalib_pci_write_config_byte(int pos, int address, unsigned char data) |
||
144 | { |
||
145 | |||
146 | pci_write_config_byte(&dev, (BYTE)address, data); |
||
147 | |||
148 | }; |
||
149 | |||
150 | void __svgalib_pci_write_config_word(int pos, int address, unsigned int data) |
||
151 | { |
||
152 | |||
153 | pci_write_config_word(&dev, (BYTE)address, data); |
||
154 | |||
155 | }; |
||
156 | |||
157 | void __svgalib_pci_write_config_dword(int pos, int address, DWORD data) |
||
158 | { |
||
159 | |||
160 | pci_write_config_dword(&dev, (BYTE)address, data); |
||
161 | |||
162 | }; |
||
163 |