2 * This file is part of the coreboot project.
4 * Copyright (C) 2014 Google Inc.
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; version 2 of the License.
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.
16 #include <console/console.h>
22 #define IOBP_RETRY 1000
24 static inline int iobp_poll(void)
28 for (try = IOBP_RETRY
; try > 0; try--) {
29 u16 status
= RCBA16(IOBPS
);
30 if ((status
& IOBPS_READY
) == 0)
35 printk(BIOS_ERR
, "IOBP: timeout waiting for transaction to complete\n");
39 u32
pch_iobp_read(u32 address
)
47 RCBA32(IOBPIRI
) = address
;
50 status
= RCBA16(IOBPS
);
51 status
&= ~IOBPS_MASK
;
53 RCBA16(IOBPS
) = status
;
55 /* Undocumented magic */
56 RCBA16(IOBPU
) = IOBPU_MAGIC
;
59 status
= RCBA16(IOBPS
);
60 status
|= IOBPS_READY
;
61 RCBA16(IOBPS
) = status
;
66 /* Check for successful transaction */
67 status
= RCBA16(IOBPS
);
68 if (status
& IOBPS_TX_MASK
) {
69 printk(BIOS_ERR
, "IOBP: read 0x%08x failed\n", address
);
77 void pch_iobp_write(u32 address
, u32 data
)
85 RCBA32(IOBPIRI
) = address
;
88 status
= RCBA16(IOBPS
);
89 status
&= ~IOBPS_MASK
;
90 status
|= IOBPS_WRITE
;
91 RCBA16(IOBPS
) = status
;
95 /* Undocumented magic */
96 RCBA16(IOBPU
) = IOBPU_MAGIC
;
99 status
= RCBA16(IOBPS
);
100 status
|= IOBPS_READY
;
101 RCBA16(IOBPS
) = status
;
106 /* Check for successful transaction */
107 status
= RCBA16(IOBPS
);
108 if (status
& IOBPS_TX_MASK
)
109 printk(BIOS_ERR
, "IOBP: write 0x%08x failed\n", address
);
112 void pch_iobp_update(u32 address
, u32 andvalue
, u32 orvalue
)
114 u32 data
= pch_iobp_read(address
);
116 /* Update the data */
120 pch_iobp_write(address
, data
);
123 void pch_iobp_exec(u32 addr
, u16 op_code
, u8 route_id
, u32
*data
, u8
*resp
)
132 /* RCBA2330[31:0] = Address */
133 RCBA32(IOBPIRI
) = addr
;
134 /* RCBA2338[15:8] = opcode */
135 RCBA16(IOBPS
) = (RCBA16(IOBPS
) & 0x00ff) | op_code
;
136 /* RCBA233A[15:8] = 0xf0 RCBA233A[7:0] = Route ID */
137 RCBA16(IOBPU
) = IOBPU_MAGIC
| route_id
;
139 RCBA32(IOBPD
) = *data
;
140 /* Set RCBA2338[0] to trigger IOBP transaction*/
141 RCBA16(IOBPS
) = RCBA16(IOBPS
) | 0x1;
146 *resp
= (RCBA16(IOBPS
) & IOBPS_TX_MASK
) >> 1;
147 *data
= RCBA32(IOBPD
);