blob: 174cda3d9571b6216ec4ca6a7cc624d94cf89f3a [file] [log] [blame]
Morgan Tsai218c2652007-11-02 16:09:58 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Morgan Tsai218c2652007-11-02 16:09:58 +00003 *
Uwe Hermannc6a10622010-10-17 19:30:58 +00004 * Copyright (C) 2007 Silicon Integrated Systems Corp. (SiS)
5 * Written by Morgan Tsai <my_tsai@sis.com> for SiS.
6 *
Morgan Tsai218c2652007-11-02 16:09:58 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Uwe Hermannc6a10622010-10-17 19:30:58 +000016 */
17
18/*
Morgan Tsai218c2652007-11-02 16:09:58 +000019 * Turn off machine check triggers when reading
20 * pci space where there are no devices.
Martin Roth226db052014-12-09 13:51:49 -070021 * This is necessary when scanning the bus for
Morgan Tsai218c2652007-11-02 16:09:58 +000022 * devices which is done by the kernel
23 *
24 * written in 2003 by Eric Biederman
25 *
26 * - Athlon64 workarounds by Stefan Reinauer
27 * - "reset once" logic by Yinghai Lu
Morgan Tsai218c2652007-11-02 16:09:58 +000028 */
29
30#include <console/console.h>
31#include <device/device.h>
32#include <device/pci.h>
33#include <device/pci_ids.h>
34#include <device/pci_ops.h>
Morgan Tsai218c2652007-11-02 16:09:58 +000035#include <pc80/mc146818rtc.h>
Morgan Tsai218c2652007-11-02 16:09:58 +000036#include <cpu/amd/model_fxx_rev.h>
Morgan Tsai218c2652007-11-02 16:09:58 +000037#include <arch/io.h>
38
Morgan Tsai218c2652007-11-02 16:09:58 +000039typedef struct msr_struct
40{
41 unsigned lo;
42 unsigned hi;
43} msr_t;
44
45static inline msr_t rdmsr(unsigned index)
46{
47 msr_t result;
48 result.lo = 0;
49 result.hi = 0;
50 return result;
51}
52
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000053/**
54 * Read resources for AGP aperture.
55 *
Martin Roth226db052014-12-09 13:51:49 -070056 * There is only one AGP aperture resource needed. The resource is added to
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000057 * the northbridge of BSP.
58 *
59 * The same trick can be used to augment legacy VGA resources which can
60 * be detect by generic PCI resource allocator for VGA devices.
61 * BAD: it is more tricky than I think, the resource allocation code is
Martin Roth226db052014-12-09 13:51:49 -070062 * implemented in a way to NOT DOING legacy VGA resource allocation on
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000063 * purpose :-(.
64 *
65 * @param dev TODO
66 */
Morgan Tsai218c2652007-11-02 16:09:58 +000067static void sis761_read_resources(device_t dev)
68{
Morgan Tsai218c2652007-11-02 16:09:58 +000069 /* Read the generic PCI resources */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000070 printk(BIOS_DEBUG, "sis761_read_resources ------->\n");
Morgan Tsai218c2652007-11-02 16:09:58 +000071 pci_dev_read_resources(dev);
72
Martin Roth226db052014-12-09 13:51:49 -070073 /* If we are not the first processor don't allocate the gart aperture */
Stefan Reinauer2b34db82009-02-28 20:10:20 +000074 if (dev->path.pci.devfn != PCI_DEVFN(0x0, 0)) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000075 printk(BIOS_DEBUG, "sis761_not_the_first_processor !!!\n");
Morgan Tsai218c2652007-11-02 16:09:58 +000076 return;
77 }
78
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000079 printk(BIOS_DEBUG, "sis761_read_resources <-------\n");
Morgan Tsai218c2652007-11-02 16:09:58 +000080 return;
81
Morgan Tsai218c2652007-11-02 16:09:58 +000082}
83
84static void sis761_set_resources(device_t dev)
85{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000086 printk(BIOS_DEBUG, "sis761_set_resources ------->\n");
Morgan Tsai218c2652007-11-02 16:09:58 +000087
88 /* Set the generic PCI resources */
89 pci_dev_set_resources(dev);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000090 printk(BIOS_DEBUG, "sis761_set_resources <-------\n");
Morgan Tsai218c2652007-11-02 16:09:58 +000091}
92
93static void sis761_init(struct device *dev)
94{
Morgan Tsai218c2652007-11-02 16:09:58 +000095 int needs_reset;
Morgan Tsai218c2652007-11-02 16:09:58 +000096 msr_t msr;
97
98
99 needs_reset = 0;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000100 printk(BIOS_DEBUG, "sis761_init: ---------->\n");
Morgan Tsai218c2652007-11-02 16:09:58 +0000101
102 msr = rdmsr(0xC001001A);
103 pci_write_config16(dev, 0x8E, msr.lo >> 16); // Topbound
104 pci_write_config8(dev, 0x7F, 0x08); // ACPI Base
105 outb(inb(0x856) | 0x40, 0x856); // Auto-Reset Function
106
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000107 printk(BIOS_DEBUG, "sis761_init: <----------\n");
Morgan Tsai218c2652007-11-02 16:09:58 +0000108}
109
110
111static struct device_operations sis761_ops = {
112 .read_resources = sis761_read_resources,
113 .set_resources = sis761_set_resources,
114 .enable_resources = pci_dev_enable_resources,
115 .init = sis761_init,
116 .scan_bus = 0,
117 .ops_pci = 0,
118};
119
120static const struct pci_driver sis761_driver __pci_driver = {
121 .ops = &sis761_ops,
122 .vendor = PCI_VENDOR_ID_SIS,
123 .device = PCI_DEVICE_ID_SIS_SIS761,
124};