summaryrefslogtreecommitdiffstats
path: root/src/northbridge/via/vx900/pcie.c
blob: 1d3ecd9938b5cc5282bae7e6597e922f03c6a93e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2013  Alexandru Gagniuc <mr.nuke.me@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <arch/io.h>
#include <console/console.h>
#include <device/pci.h>
#include <device/pciexp.h>
#include <device/pci_ids.h>

#include "vx900.h"

/**
 * @file vx900/pcie.c
 *
 * STATUS:
 * We do part of the sequence to initialize the PCIE link. The problem is that
 * the reset signal for each slot is connected to a GPO pin, but We don't know
 * which GPO pin. We need to figure out which GPIO pin is hooked to which slot,
 * and have a mechanism to specify this per-mainboard (devicetree.cb).
 *
 * There is currently no timeout detection mechanism for when a link comes up.
 * If the link never comes up, we hang.
 */

static void vx900_pcie_link_init(struct device *dev)
{
	u8 reg8;
	u32 reg32;

	u8 fn = dev->path.pci.devfn & 0x07;

	/* Step 1 : Check for presence of PCIE device */
	reg8 = pci_read_config8(dev, 0x5a);

	if (reg8 & (1 << 6))
		printk(BIOS_DEBUG, "Card detected in PEX%i\n", fn);
	else
		return;

	/* Step 2: Wait for device to enter L0 state */
	/* FIXME: implement timeout detection */
	while (0x8a != pci_read_config8(dev, 0x1c3));

	/* Step 3: Clear PCIe error status, then check for failures */
	pci_write_config32(dev, 0x104, 0xffffffff);
	reg32 = pci_read_config32(dev, 0x104);
	if (0 != reg32) {
		printk(BIOS_DEBUG, "PEX init error. flags 0x%.8x\n", reg32);
		return;
	}

	pci_write_config32(dev, 0x110, 0xffffffff);
	reg32 = pci_read_config32(dev, 0x110);
	if (0 != reg32)
		printk(BIOS_DEBUG, "PEX errors. flags 0x%.8x\n", reg32);

	pci_write_config8(dev, 0xa4, 0xff);
	if (pci_read_config8(dev, 0x4a) & (1 << 3))
		printk(BIOS_DEBUG, "Unsupported request detected.\n");

	pci_write_config8(dev, 0x15a, 0xff);
	if (pci_read_config8(dev, 0x15a) & (1 << 1))
		printk(BIOS_DEBUG, "Negotiation pending.\n");

	/* Step 4: Read vendor ID */
	/* FIXME: Do we want to run through the whole sequence and delay boot
	 * by several seconds if the device does not respond properly the first
	 * time? */
}

static void vx900_pex_dev_set_resources(struct device *dev)
{
	assign_resources(dev->link_list);
}

static void vx900_pex_init(struct device *dev)
{
	/* FIXME: For some reason, PEX0 hangs on init. Find issue, fix it. */
	if ((dev->path.pci.devfn & 0x7) == 0)
		return;

	vx900_pcie_link_init(dev);
}

static struct device_operations vx900_pex_ops = {
	.read_resources = pci_bus_read_resources,
	.set_resources = vx900_pex_dev_set_resources,
	.enable_resources = pci_bus_enable_resources,
	.init = vx900_pex_init,
	.scan_bus = pciexp_scan_bridge,
	.reset_bus = pci_bus_reset,
};

static const unsigned short pci_device_ids[] = {
	PCI_DEVICE_ID_VIA_VX900_PEX1,
	PCI_DEVICE_ID_VIA_VX900_PEX2,
	PCI_DEVICE_ID_VIA_VX900_PEX3,
	PCI_DEVICE_ID_VIA_VX900_PEX4,
	0,
};

static const struct pci_driver pex_driver __pci_driver = {
	.ops = &vx900_pex_ops,
	.vendor = PCI_VENDOR_ID_VIA,
	.devices = pci_device_ids,

};