blob: 622931520fdd74e9dbff28ea578a90f663335ce8 [file] [log] [blame]
zbao246e84b2012-07-13 18:47:03 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, 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; 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.
zbao246e84b2012-07-13 18:47:03 +080014 */
15
Elyes HAOUAS65fa5982014-07-22 23:12:38 +020016#ifndef _HUDSON_EARLY_SETUP_C_
17#define _HUDSON_EARLY_SETUP_C_
zbao246e84b2012-07-13 18:47:03 +080018
19#include <stdint.h>
Stefan Reinauer24d1d4b2013-03-21 11:51:41 -070020#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
zbao246e84b2012-07-13 18:47:03 +080022#include <arch/acpi.h>
23#include <console/console.h>
24#include <reset.h>
zbao246e84b2012-07-13 18:47:03 +080025#include "hudson.h"
26
Idwer Volleringc18e5212014-01-06 21:57:56 +000027void hudson_pci_port80(void)
28{
29 u8 byte;
Antonello Dettori8d7181d2016-09-01 16:50:42 +020030 pci_devfn_t dev;
Idwer Volleringc18e5212014-01-06 21:57:56 +000031
32 /* P2P Bridge */
33 dev = PCI_DEV(0, 0x14, 4);
34
35 /* Chip Control: Enable subtractive decoding */
36 byte = pci_read_config8(dev, 0x40);
37 byte |= 1 << 5;
38 pci_write_config8(dev, 0x40, byte);
39
40 /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
41 byte = pci_read_config8(dev, 0x4B);
42 byte |= 1 << 7;
43 pci_write_config8(dev, 0x4B, byte);
44
45 /* The same IO Base and IO Limit here is meaningful because we set the
46 * bridge to be subtractive. During early setup stage, we have to make
47 * sure that data can go through port 0x80.
48 */
49 /* IO Base: 0xf000 */
50 byte = pci_read_config8(dev, 0x1C);
51 byte |= 0xF << 4;
52 pci_write_config8(dev, 0x1C, byte);
53
54 /* IO Limit: 0xf000 */
55 byte = pci_read_config8(dev, 0x1D);
56 byte |= 0xF << 4;
57 pci_write_config8(dev, 0x1D, byte);
58
59 /* PCI Command: Enable IO response */
60 byte = pci_read_config8(dev, 0x04);
61 byte |= 1 << 0;
62 pci_write_config8(dev, 0x04, byte);
63
64 /* LPC controller */
65 dev = PCI_DEV(0, 0x14, 3);
66
67 byte = pci_read_config8(dev, 0x4A);
68 byte &= ~(1 << 5); /* disable lpc port 80 */
69 pci_write_config8(dev, 0x4A, byte);
70}
71
zbao246e84b2012-07-13 18:47:03 +080072void hudson_lpc_port80(void)
73{
74 u8 byte;
Antonello Dettori8d7181d2016-09-01 16:50:42 +020075 pci_devfn_t dev;
zbao246e84b2012-07-13 18:47:03 +080076
77 /* Enable LPC controller */
78 outb(0xEC, 0xCD6);
79 byte = inb(0xCD7);
80 byte |= 1;
81 outb(0xEC, 0xCD6);
82 outb(byte, 0xCD7);
83
84 /* Enable port 80 LPC decode in pci function 3 configuration space. */
Idwer Volleringc18e5212014-01-06 21:57:56 +000085 dev = PCI_DEV(0, 0x14, 3);
zbao246e84b2012-07-13 18:47:03 +080086 byte = pci_read_config8(dev, 0x4a);
Idwer Volleringc18e5212014-01-06 21:57:56 +000087 byte |= 1 << 5; /* enable port 80 */
zbao246e84b2012-07-13 18:47:03 +080088 pci_write_config8(dev, 0x4a, byte);
89}
90
91int s3_save_nvram_early(u32 dword, int size, int nvram_pos)
92{
93 int i;
94 printk(BIOS_DEBUG, "Writing %x of size %d to nvram pos: %d\n", dword, size, nvram_pos);
95
Elyes HAOUASc021ffe2016-09-18 19:18:56 +020096 for (i = 0; i < size; i++) {
zbao246e84b2012-07-13 18:47:03 +080097 outb(nvram_pos, BIOSRAM_INDEX);
Elyes HAOUASa342f392018-10-17 10:56:26 +020098 outb((dword >> (8 * i)) & 0xff, BIOSRAM_DATA);
zbao246e84b2012-07-13 18:47:03 +080099 nvram_pos++;
100 }
101
102 return nvram_pos;
103}
104
105int s3_load_nvram_early(int size, u32 *old_dword, int nvram_pos)
106{
107 u32 data = *old_dword;
108 int i;
Elyes HAOUASc021ffe2016-09-18 19:18:56 +0200109 for (i = 0; i < size; i++) {
zbao246e84b2012-07-13 18:47:03 +0800110 outb(nvram_pos, BIOSRAM_INDEX);
111 data &= ~(0xff << (i * 8));
112 data |= inb(BIOSRAM_DATA) << (i *8);
113 nvram_pos++;
114 }
115 *old_dword = data;
116 printk(BIOS_DEBUG, "Loading %x of size %d to nvram pos:%d\n", *old_dword, size,
117 nvram_pos-size);
118 return nvram_pos;
119}
120
Edward O'Callaghan893a55e2014-12-02 17:44:47 +1100121#endif /* _HUDSON_EARLY_SETUP_C_ */