Debian Codegraph @

src/cpu/intel/haswell/pcode_mailbox.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <console/console.h>
4 #include <delay.h>
5 #include <northbridge/intel/haswell/haswell.h>
6 #include <types.h>
7
8 #include "haswell.h"
9
10 int pcode_ready(void)
11 {
12 int wait_count;
13 const int delay_step = 10;
14
15 wait_count = 0;
16 do {
17 if (!(mchbar_read32(BIOS_MAILBOX_INTERFACE) & MAILBOX_RUN_BUSY))
18 return 0;
19 wait_count += delay_step;
20 udelay(delay_step);
21 } while (wait_count < 1000);
22
23 return -1;
24 }
25
26 u32 pcode_mailbox_read(u32 command)
27 {
28 if (pcode_ready() < 0) {
29 printk(BIOS_ERR, "PCODE: mailbox timeout on wait ready.\n");
30 return 0;
31 }
32
33 /* Send command and start transaction */
34 mchbar_write32(BIOS_MAILBOX_INTERFACE, command | MAILBOX_RUN_BUSY);
35
36 if (pcode_ready() < 0) {
37 printk(BIOS_ERR, "PCODE: mailbox timeout on completion.\n");
38 return 0;
39 }
40
41 /* Read mailbox */
42 return mchbar_read32(BIOS_MAILBOX_DATA);
43 }
44
45 int pcode_mailbox_write(u32 command, u32 data)
46 {
47 if (pcode_ready() < 0) {
48 printk(BIOS_ERR, "PCODE: mailbox timeout on wait ready.\n");
49 return -1;
50 }
51
52 mchbar_write32(BIOS_MAILBOX_DATA, data);
53
54 /* Send command and start transaction */
55 mchbar_write32(BIOS_MAILBOX_INTERFACE, command | MAILBOX_RUN_BUSY);
56
57 if (pcode_ready() < 0) {
58 printk(BIOS_ERR, "PCODE: mailbox timeout on completion.\n");
59 return -1;
60 }
61
62 return 0;
63 }