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