Various license header consistency fixes (trivial).
[coreboot.git] / src / northbridge / via / vx800 / pci_rawops.h
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 One Laptop per Child, Association, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #ifndef ARCH_I386_PCI_RAWOPS_H
22 # define ARCH_I386_PCI_RAWOPS_H 1
23 #include <stdint.h>
24
25 #define PCI_RAWDEV(SEGBUS, DEV, FN) ( \
26         (((SEGBUS) & 0xFFF) << 20) | \
27         (((DEV) & 0x1F) << 15) | \
28         (((FN)  & 0x07) << 12))
29 struct  VIA_PCI_REG_INIT_TABLE {
30         u8 ChipRevisionStart;
31         u8 ChipRevisionEnd;
32         u8 Bus;
33         u8 Device;
34         u8 Function;
35         u32 Register;
36         u8 Mask;
37         u8 Value;
38 };
39 typedef unsigned device_t_raw; /* pci and pci_mmio need to have different ways to have dev */
40
41 /* FIXME: We need to make the coreboot to run at 64bit mode, So when read/write memory above 4G,
42  * We don't need to set %fs, and %gs anymore
43  * Before that We need to use %gs, and leave %fs to other RAM access
44  */
45  uint8_t pci_io_rawread_config8(device_t_raw dev, unsigned where)
46 {
47         unsigned addr;
48 #if PCI_IO_CFG_EXT == 0
49         addr = (dev>>4) | where;
50 #else
51         addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16); //seg == 0
52 #endif
53         outl(0x80000000 | (addr & ~3), 0xCF8);
54         return inb(0xCFC + (addr & 3));
55 }
56
57 #if MMCONF_SUPPORT
58  uint8_t pci_mmio_rawread_config8(device_t_raw dev, unsigned where)
59 {
60         unsigned addr;
61         addr = dev | where;
62         return read8x(addr);
63 }
64 #endif
65  uint8_t pci_rawread_config8(device_t_raw dev, unsigned where)
66 {
67 #if MMCONF_SUPPORT
68         return pci_mmio_rawread_config8(dev, where);
69 #else
70         return pci_io_rawread_config8(dev, where);
71 #endif
72 }
73
74  uint16_t pci_io_rawread_config16(device_t_raw dev, unsigned where)
75 {
76         unsigned addr;
77 #if PCI_IO_CFG_EXT == 0
78         addr = (dev>>4) | where;
79 #else
80         addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
81 #endif
82         outl(0x80000000 | (addr & ~3), 0xCF8);
83         return inw(0xCFC + (addr & 2));
84 }
85
86 #if MMCONF_SUPPORT
87  uint16_t pci_mmio_rawread_config16(device_t_raw dev, unsigned where)
88 {
89         unsigned addr;
90         addr = dev | where;
91         return read16x(addr);
92 }
93 #endif
94
95  uint16_t pci_rawread_config16(device_t_raw dev, unsigned where)
96 {
97 #if MMCONF_SUPPORT
98         return pci_mmio_rawread_config16(dev, where);
99 #else
100         return pci_io_rawread_config16(dev, where);
101 #endif
102 }
103
104
105  uint32_t pci_io_rawread_config32(device_t_raw dev, unsigned where)
106 {
107         unsigned addr;
108 #if PCI_IO_CFG_EXT == 0
109         addr = (dev>>4) | where;
110 #else
111         addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
112 #endif
113         outl(0x80000000 | (addr & ~3), 0xCF8);
114         return inl(0xCFC);
115 }
116
117 #if MMCONF_SUPPORT
118  uint32_t pci_mmio_rawread_config32(device_t_raw dev, unsigned where)
119 {
120         unsigned addr;
121         addr = dev | where;
122         return read32x(addr);
123 }
124 #endif
125
126  uint32_t pci_rawread_config32(device_t_raw dev, unsigned where)
127 {
128 #if MMCONF_SUPPORT
129         return pci_mmio_rawread_config32(dev, where);
130 #else
131         return pci_io_rawread_config32(dev, where);
132 #endif
133 }
134
135  void pci_io_rawwrite_config8(device_t_raw dev, unsigned where, uint8_t value)
136 {
137         unsigned addr;
138 #if PCI_IO_CFG_EXT == 0
139         addr = (dev>>4) | where;
140 #else
141         addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
142 #endif
143         outl(0x80000000 | (addr & ~3), 0xCF8);
144         outb(value, 0xCFC + (addr & 3));
145 }
146
147 #if MMCONF_SUPPORT
148  void pci_mmio_rawwrite_config8(device_t_raw dev, unsigned where, uint8_t value)
149 {
150         unsigned addr;
151         addr = dev | where;
152         write8x(addr, value);
153 }
154 #endif
155
156  void pci_rawwrite_config8(device_t_raw dev, unsigned where, uint8_t value)
157 {
158 #if MMCONF_SUPPORT
159         pci_mmio_rawwrite_config8(dev, where, value);
160 #else
161         pci_io_rawwrite_config8(dev, where, value);
162 #endif
163 }
164
165
166  void pci_io_rawwrite_config16(device_t_raw dev, unsigned where, uint16_t value)
167 {
168         unsigned addr;
169 #if PCI_IO_CFG_EXT == 0
170         addr = (dev>>4) | where;
171 #else
172         addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
173 #endif
174         outl(0x80000000 | (addr & ~3), 0xCF8);
175         outw(value, 0xCFC + (addr & 2));
176 }
177
178 #if MMCONF_SUPPORT
179  void pci_mmio_rawwrite_config16(device_t_raw dev, unsigned where, uint16_t value)
180 {
181         unsigned addr;
182         addr = dev | where;
183         write16x(addr, value);
184 }
185 #endif
186
187  void pci_rawwrite_config16(device_t_raw dev, unsigned where, uint16_t value)
188 {
189 #if MMCONF_SUPPORT
190         pci_mmio_rawwrite_config16(dev, where, value);
191 #else
192         pci_io_rawwrite_config16(dev, where, value);
193 #endif
194 }
195
196
197  void pci_io_rawwrite_config32(device_t_raw dev, unsigned where, uint32_t value)
198 {
199         unsigned addr;
200 #if PCI_IO_CFG_EXT == 0
201         addr = (dev>>4) | where;
202 #else
203         addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
204 #endif
205         outl(0x80000000 | (addr & ~3), 0xCF8);
206         outl(value, 0xCFC);
207 }
208
209 #if MMCONF_SUPPORT
210  void pci_mmio_rawwrite_config32(device_t_raw dev, unsigned where, uint32_t value)
211 {
212         unsigned addr;
213         addr = dev | where;
214         write32x(addr, value);
215 }
216 #endif
217
218  void pci_rawwrite_config32(device_t_raw dev, unsigned where, uint32_t value)
219 {
220 #if MMCONF_SUPPORT
221         pci_mmio_rawwrite_config32(dev, where, value);
222 #else
223         pci_io_rawwrite_config32(dev, where, value);
224 #endif
225 }
226
227
228 void pci_rawmodify_config8(device_t_raw dev, unsigned where, u8 orval,u8 mask)
229 {     u8 data=pci_rawread_config8(dev,where);
230        data&=(~mask);
231        data|=orval;
232        pci_rawwrite_config8(dev,where,data);
233 }
234 void pci_rawmodify_config16(device_t_raw dev, unsigned where, uint16_t orval,uint16_t mask)
235 {     uint16_t data=pci_rawread_config16(dev,where);
236        data&=(~mask);
237        data|=orval;
238        pci_rawwrite_config16(dev,where,data);
239 }
240 void pci_rawmodify_config32(device_t_raw dev, unsigned where, uint32_t orval,uint32_t mask)
241 {     uint32_t data=pci_rawread_config32(dev,where);
242        data&=(~mask);
243        data|=orval;
244        pci_rawwrite_config32(dev,where,data);
245 }
246
247 void io_rawmodify_config8(u16 where, uint8_t orval,uint8_t mask)
248 {
249         u8 data=inb(where);
250        data&=(~mask);
251        data|=orval;
252        outb(data,where);
253 }
254
255 void via_pci_inittable(u8 chipversion,struct VIA_PCI_REG_INIT_TABLE* initdata)
256 {
257         u8 i=0;
258         device_t_raw devbxdxfx;
259         for(i=0;;i++)   {
260                         if((initdata[i].Mask==0)&&(initdata[i].Value==0)&&(initdata[i].Bus==0)&&(initdata[i].ChipRevisionEnd==0xff)&&(initdata[i].ChipRevisionStart==0)&&(initdata[i].Device==0)&&(initdata[i].Function==0)&&(initdata[i].Register==0))
261                                 break;
262                         if((chipversion>=initdata[i].ChipRevisionStart)&&(chipversion<=initdata[i].ChipRevisionEnd)){
263                                 devbxdxfx=PCI_RAWDEV(initdata[i].Bus,initdata[i].Device,initdata[i].Function);
264                                 pci_rawmodify_config8(devbxdxfx, initdata[i].Register,initdata[i].Value,initdata[i].Mask);
265                         }
266         }
267 }
268 #endif