Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007 Silicon Integrated Systems Corp. (SiS) |
| 5 | * Written by Morgan Tsai <my_tsai@sis.com> for SiS. |
| 6 | * |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 7 | * 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 Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | /* |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 19 | * Turn off machine check triggers when reading |
| 20 | * pci space where there are no devices. |
Martin Roth | 226db05 | 2014-12-09 13:51:49 -0700 | [diff] [blame] | 21 | * This is necessary when scanning the bus for |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 22 | * 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 Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 28 | */ |
| 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 Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 35 | #include <pc80/mc146818rtc.h> |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 36 | #include <cpu/amd/model_fxx_rev.h> |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 37 | #include <arch/io.h> |
| 38 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 39 | typedef struct msr_struct |
| 40 | { |
| 41 | unsigned lo; |
| 42 | unsigned hi; |
| 43 | } msr_t; |
| 44 | |
| 45 | static 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 Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 53 | /** |
| 54 | * Read resources for AGP aperture. |
| 55 | * |
Martin Roth | 226db05 | 2014-12-09 13:51:49 -0700 | [diff] [blame] | 56 | * There is only one AGP aperture resource needed. The resource is added to |
Uwe Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 57 | * 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 Roth | 226db05 | 2014-12-09 13:51:49 -0700 | [diff] [blame] | 62 | * implemented in a way to NOT DOING legacy VGA resource allocation on |
Uwe Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 63 | * purpose :-(. |
| 64 | * |
| 65 | * @param dev TODO |
| 66 | */ |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 67 | static void sis761_read_resources(device_t dev) |
| 68 | { |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 69 | /* Read the generic PCI resources */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 70 | printk(BIOS_DEBUG, "sis761_read_resources ------->\n"); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 71 | pci_dev_read_resources(dev); |
| 72 | |
Martin Roth | 226db05 | 2014-12-09 13:51:49 -0700 | [diff] [blame] | 73 | /* If we are not the first processor don't allocate the gart aperture */ |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 74 | if (dev->path.pci.devfn != PCI_DEVFN(0x0, 0)) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 75 | printk(BIOS_DEBUG, "sis761_not_the_first_processor !!!\n"); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 76 | return; |
| 77 | } |
| 78 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 79 | printk(BIOS_DEBUG, "sis761_read_resources <-------\n"); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 80 | return; |
| 81 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static void sis761_set_resources(device_t dev) |
| 85 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 86 | printk(BIOS_DEBUG, "sis761_set_resources ------->\n"); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 87 | |
| 88 | /* Set the generic PCI resources */ |
| 89 | pci_dev_set_resources(dev); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 90 | printk(BIOS_DEBUG, "sis761_set_resources <-------\n"); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static void sis761_init(struct device *dev) |
| 94 | { |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 95 | int needs_reset; |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 96 | msr_t msr; |
| 97 | |
| 98 | |
| 99 | needs_reset = 0; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 100 | printk(BIOS_DEBUG, "sis761_init: ---------->\n"); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 101 | |
| 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 Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 107 | printk(BIOS_DEBUG, "sis761_init: <----------\n"); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
| 111 | static 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 | |
| 120 | static 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 | }; |