Fix a few whitespace and coding style issues.
[coreboot.git] / src / northbridge / intel / sch / port_access.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009-2010 iWave Systems
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <stdint.h>
21 #include <arch/io.h>
22 #include <arch/romcc_io.h>
23 #include <device/pci_def.h>
24 #include <device/pnp_def.h>
25 #include <cpu/x86/lapic.h>
26 #include "sch.h"
27
28 /*
29  * Restricted Access Regions:
30  *
31  * MCR - Message Control Register
32  * 31        24              16                 8              4              0
33  * ----------------------------------------------------------------------------
34  * |          |               |    Target       |   Write      |              |
35  * | Opcode   |  Port         |    register     |   byte       |   Reserved   |
36  * |          |               |    Address      |   Enables    |              |
37  * ----------------------------------------------------------------------------
38  *
39  * MDR - Message Data Register
40  * 31                                                                         0
41  * ----------------------------------------------------------------------------
42  * |                                                                          |
43  * |                            Data                                          |
44  * |                                                                          |
45  * ----------------------------------------------------------------------------
46  */
47
48 #define MSG_OPCODE_READ  0xD0000000
49 #define MSG_OPCODE_WRITE 0xE0000000
50
51 #define MCR 0xD0
52 #define MDR 0xD4
53
54 int sch_port_access_read(int port, int reg, int bytes)
55 {
56         pci_write_config32(PCI_DEV(0, 0, 0), MCR,
57                            (MSG_OPCODE_READ | (port << 16) | (reg << 8)));
58         return pci_read_config32(PCI_DEV(0, 0, 0), MDR);
59 }
60
61 void sch_port_access_write(int port, int reg, int bytes, long data)
62 {
63         pci_write_config32(PCI_DEV(0, 0, 0), MDR, data);
64         pci_write_config32(PCI_DEV(0, 0, 0), MCR,
65                            (MSG_OPCODE_WRITE | (port << 16) | (reg << 8)));
66         pci_read_config32(PCI_DEV(0, 0, 0), MDR);
67 }
68
69 void sch_port_access_write_ram_cmd(int cmd, int port, int reg, int data)
70 {
71         pci_write_config32(PCI_DEV(0, 0, 0), MDR, data);
72         pci_write_config32(PCI_DEV(0, 0, 0), MCR,
73                            ((cmd << 24) | (port << 16) | (reg << 8)));
74         pci_read_config32(PCI_DEV(0, 0, 0), MDR);
75 }