blob: c3a4d41c8e59988d18c65dd9e68def092fc660e6 [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 <console/console.h>
Elyes HAOUASeb789f02018-10-27 16:40:25 +020023
zbao246e84b2012-07-13 18:47:03 +080024#include "hudson.h"
25
Idwer Volleringc18e5212014-01-06 21:57:56 +000026void hudson_pci_port80(void)
27{
28 u8 byte;
Antonello Dettori8d7181d2016-09-01 16:50:42 +020029 pci_devfn_t dev;
Idwer Volleringc18e5212014-01-06 21:57:56 +000030
31 /* P2P Bridge */
32 dev = PCI_DEV(0, 0x14, 4);
33
34 /* Chip Control: Enable subtractive decoding */
35 byte = pci_read_config8(dev, 0x40);
36 byte |= 1 << 5;
37 pci_write_config8(dev, 0x40, byte);
38
39 /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
40 byte = pci_read_config8(dev, 0x4B);
41 byte |= 1 << 7;
42 pci_write_config8(dev, 0x4B, byte);
43
44 /* The same IO Base and IO Limit here is meaningful because we set the
45 * bridge to be subtractive. During early setup stage, we have to make
46 * sure that data can go through port 0x80.
47 */
48 /* IO Base: 0xf000 */
49 byte = pci_read_config8(dev, 0x1C);
50 byte |= 0xF << 4;
51 pci_write_config8(dev, 0x1C, byte);
52
53 /* IO Limit: 0xf000 */
54 byte = pci_read_config8(dev, 0x1D);
55 byte |= 0xF << 4;
56 pci_write_config8(dev, 0x1D, byte);
57
58 /* PCI Command: Enable IO response */
59 byte = pci_read_config8(dev, 0x04);
60 byte |= 1 << 0;
61 pci_write_config8(dev, 0x04, byte);
62
63 /* LPC controller */
64 dev = PCI_DEV(0, 0x14, 3);
65
66 byte = pci_read_config8(dev, 0x4A);
67 byte &= ~(1 << 5); /* disable lpc port 80 */
68 pci_write_config8(dev, 0x4A, byte);
69}
70
zbao246e84b2012-07-13 18:47:03 +080071void hudson_lpc_port80(void)
72{
73 u8 byte;
Antonello Dettori8d7181d2016-09-01 16:50:42 +020074 pci_devfn_t dev;
zbao246e84b2012-07-13 18:47:03 +080075
76 /* Enable LPC controller */
77 outb(0xEC, 0xCD6);
78 byte = inb(0xCD7);
79 byte |= 1;
80 outb(0xEC, 0xCD6);
81 outb(byte, 0xCD7);
82
83 /* Enable port 80 LPC decode in pci function 3 configuration space. */
Idwer Volleringc18e5212014-01-06 21:57:56 +000084 dev = PCI_DEV(0, 0x14, 3);
zbao246e84b2012-07-13 18:47:03 +080085 byte = pci_read_config8(dev, 0x4a);
Idwer Volleringc18e5212014-01-06 21:57:56 +000086 byte |= 1 << 5; /* enable port 80 */
zbao246e84b2012-07-13 18:47:03 +080087 pci_write_config8(dev, 0x4a, byte);
88}
89
90int s3_save_nvram_early(u32 dword, int size, int nvram_pos)
91{
92 int i;
93 printk(BIOS_DEBUG, "Writing %x of size %d to nvram pos: %d\n", dword, size, nvram_pos);
94
Elyes HAOUASc021ffe2016-09-18 19:18:56 +020095 for (i = 0; i < size; i++) {
zbao246e84b2012-07-13 18:47:03 +080096 outb(nvram_pos, BIOSRAM_INDEX);
Elyes HAOUASa342f392018-10-17 10:56:26 +020097 outb((dword >> (8 * i)) & 0xff, BIOSRAM_DATA);
zbao246e84b2012-07-13 18:47:03 +080098 nvram_pos++;
99 }
100
101 return nvram_pos;
102}
103
104int s3_load_nvram_early(int size, u32 *old_dword, int nvram_pos)
105{
106 u32 data = *old_dword;
107 int i;
Elyes HAOUASc021ffe2016-09-18 19:18:56 +0200108 for (i = 0; i < size; i++) {
zbao246e84b2012-07-13 18:47:03 +0800109 outb(nvram_pos, BIOSRAM_INDEX);
110 data &= ~(0xff << (i * 8));
111 data |= inb(BIOSRAM_DATA) << (i *8);
112 nvram_pos++;
113 }
114 *old_dword = data;
115 printk(BIOS_DEBUG, "Loading %x of size %d to nvram pos:%d\n", *old_dword, size,
116 nvram_pos-size);
117 return nvram_pos;
118}
119
Edward O'Callaghan893a55e2014-12-02 17:44:47 +1100120#endif /* _HUDSON_EARLY_SETUP_C_ */