blob: 63bce7b071e81a81809975715fecf6abfaae2a80 [file] [log] [blame]
Alexandru Gagniuc599d6682014-04-17 23:33:50 -05001/*
Martin Rothebace9f2018-05-26 18:56:17 -06002 * This file is part of the coreboot project.
Alexandru Gagniuc599d6682014-04-17 23:33:50 -05003 *
4 * Copyright (C) 2014 Alexandru Gagniuc <mr.nuke.me@gmail.com>
Martin Rothebace9f2018-05-26 18:56:17 -06005 *
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, or (at your
9 * 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
17/*
18 * SMM utilities used in both SMM and normal mode
Alexandru Gagniuc599d6682014-04-17 23:33:50 -050019 */
20
21#include "smi.h"
22
23#include <console/console.h>
24
25#define HUDSON_SMI_ACPI_COMMAND 75
26
27static void configure_smi(uint8_t smi_num, uint8_t mode)
28{
29 uint8_t reg32_offset, bit_offset;
30 uint32_t reg32;
31
32 /* SMI sources range from [0:149] */
33 if (smi_num > 149) {
34 printk(BIOS_WARNING, "BUG: Invalid SMI: %u\n", smi_num);
35 return;
36 }
37
38 /* 16 sources per register, 2 bits per source; registers are 4 bytes */
39 reg32_offset = (smi_num / 16) * 4;
40 bit_offset = (smi_num % 16) * 2;
41
42 reg32 = smi_read32(SMI_REG_CONTROL0 + reg32_offset);
43 reg32 &= ~(0x3 << (bit_offset));
44 reg32 |= (mode & 0x3) << bit_offset;
45 smi_write32(SMI_REG_CONTROL0 + reg32_offset, reg32);
46}
47
48/**
49 * Configure generation of interrupts for given GEVENT pin
50 *
51 * @param gevent The GEVENT pin number. Valid values are 0 thru 23
52 * @param mode The type of event this pin should generate. Note that only
53 * SMI_MODE_SMI generates an SMI. SMI_MODE_DISABLE disables events.
54 * @param level SMI_LVL_LOW or SMI_LVL_HIGH
55 */
56void hudson_configure_gevent_smi(uint8_t gevent, uint8_t mode, uint8_t level)
57{
58 uint32_t reg32;
59 /* GEVENT pins range from [0:23] */
60 if (gevent > 23) {
61 printk(BIOS_WARNING, "BUG: Invalid GEVENT: %u\n", gevent);
62 return;
63 }
64
65 /* SMI0 source is GEVENT0 and so on */
66 configure_smi(gevent, mode);
67
68 /* And set set the trigger level */
69 reg32 = smi_read32(SMI_REG_SMITRIG0);
70 reg32 &= ~(1 << gevent);
71 reg32 |= (level & 0x1) << gevent;
72 smi_write32(SMI_REG_SMITRIG0, reg32);
73}
74
75/** Disable events from given GEVENT pin */
76void hudson_disable_gevent_smi(uint8_t gevent)
77{
78 /* GEVENT pins range from [0:23] */
79 if (gevent > 23) {
80 printk(BIOS_WARNING, "BUG: Invalid GEVENT: %u\n", gevent);
81 return;
82 }
83
84 /* SMI0 source is GEVENT0 and so on */
85 configure_smi(gevent, SMI_MODE_DISABLE);
86}
87
88/** Enable SMIs on writes to ACPI SMI command port */
89void hudson_enable_acpi_cmd_smi(void)
90{
91 configure_smi(HUDSON_SMI_ACPI_COMMAND, SMI_MODE_SMI);
92}