Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2006 Eric Biederman (ebiederm@xmission.com) |
| 5 | * Copyright (C) 2007 AMD |
| 6 | * |
| 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; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stddef.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/pci_ehci.h> |
| 20 | #include <arch/io.h> |
| 21 | #include <device/pci.h> |
| 22 | #include <device/pci_def.h> |
| 23 | #include <string.h> |
| 24 | |
| 25 | #include "ehci_debug.h" |
| 26 | #include "ehci.h" |
| 27 | |
| 28 | #if !defined(__PRE_RAM__) && !defined(__SMM__) |
| 29 | static struct device_operations *ehci_drv_ops; |
| 30 | static struct device_operations ehci_dbg_ops; |
| 31 | #endif |
| 32 | |
Kyösti Mälkki | 6f6a249 | 2014-02-09 19:21:30 +0200 | [diff] [blame] | 33 | int ehci_debug_hw_enable(unsigned int *base, unsigned int *dbg_offset) |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 34 | { |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 35 | pci_devfn_t dbg_dev = pci_ehci_dbg_dev(CONFIG_USBDEBUG_HCD_INDEX); |
| 36 | pci_ehci_dbg_enable(dbg_dev, CONFIG_EHCI_BAR); |
Kyösti Mälkki | 6f6a249 | 2014-02-09 19:21:30 +0200 | [diff] [blame] | 37 | #ifdef __SIMPLE_DEVICE__ |
| 38 | pci_devfn_t dev = dbg_dev; |
| 39 | #else |
| 40 | device_t dev = dev_find_slot(PCI_DEV2SEGBUS(dbg_dev), PCI_DEV2DEVFN(dbg_dev)); |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 41 | #endif |
Kyösti Mälkki | 6f6a249 | 2014-02-09 19:21:30 +0200 | [diff] [blame] | 42 | |
| 43 | u8 pos = pci_find_capability(dev, PCI_CAP_ID_EHCI_DEBUG); |
| 44 | if (!pos) |
| 45 | return -1; |
| 46 | |
| 47 | u32 cap = pci_read_config32(dev, pos); |
| 48 | |
| 49 | /* FIXME: We should remove static EHCI_BAR_INDEX. */ |
| 50 | u8 dbg_bar = 0x10 + 4 * ((cap >> 29) - 1); |
| 51 | if (dbg_bar != EHCI_BAR_INDEX) |
| 52 | return -1; |
| 53 | |
| 54 | *base = CONFIG_EHCI_BAR; |
| 55 | *dbg_offset = (cap>>16) & 0x1ffc; |
| 56 | return 0; |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void ehci_debug_select_port(unsigned int port) |
| 60 | { |
| 61 | pci_devfn_t dbg_dev = pci_ehci_dbg_dev(CONFIG_USBDEBUG_HCD_INDEX); |
| 62 | pci_ehci_dbg_set_port(dbg_dev, port); |
| 63 | } |
| 64 | |
| 65 | #if !defined(__PRE_RAM__) && !defined(__SMM__) |
| 66 | static void pci_ehci_set_resources(struct device *dev) |
| 67 | { |
| 68 | struct resource *res; |
| 69 | |
| 70 | printk(BIOS_DEBUG, "%s EHCI Debug Port hook triggered\n", dev_path(dev)); |
| 71 | usbdebug_disable(); |
| 72 | |
| 73 | if (ehci_drv_ops->set_resources) |
| 74 | ehci_drv_ops->set_resources(dev); |
| 75 | res = find_resource(dev, EHCI_BAR_INDEX); |
| 76 | if (!res) |
| 77 | return; |
| 78 | |
| 79 | usbdebug_re_enable((u32)res->base); |
| 80 | report_resource_stored(dev, res, ""); |
| 81 | printk(BIOS_DEBUG, "%s EHCI Debug Port relocated\n", dev_path(dev)); |
| 82 | } |
| 83 | |
| 84 | void pci_ehci_read_resources(struct device *dev) |
| 85 | { |
| 86 | pci_devfn_t dbg_dev = pci_ehci_dbg_dev(CONFIG_USBDEBUG_HCD_INDEX); |
| 87 | |
| 88 | if (!ehci_drv_ops && pci_match_simple_dev(dev, dbg_dev)) { |
| 89 | memcpy(&ehci_dbg_ops, dev->ops, sizeof(ehci_dbg_ops)); |
| 90 | ehci_drv_ops = dev->ops; |
| 91 | ehci_dbg_ops.set_resources = pci_ehci_set_resources; |
| 92 | dev->ops = &ehci_dbg_ops; |
| 93 | printk(BIOS_DEBUG, "%s EHCI BAR hook registered\n", dev_path(dev)); |
| 94 | } else { |
| 95 | printk(BIOS_DEBUG, "More than one caller of %s from %s\n", __func__, dev_path(dev)); |
| 96 | } |
| 97 | |
| 98 | pci_dev_read_resources(dev); |
| 99 | } |
| 100 | #endif |
| 101 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 102 | u8 *pci_ehci_base_regs(pci_devfn_t sdev) |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 103 | { |
| 104 | #ifdef __SIMPLE_DEVICE__ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 105 | u8 *base = (u8 *)(pci_read_config32(sdev, EHCI_BAR_INDEX) & ~0x0f); |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 106 | #else |
| 107 | device_t dev = dev_find_slot(PCI_DEV2SEGBUS(sdev), PCI_DEV2DEVFN(sdev)); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 108 | u8 *base = (u8 *)(pci_read_config32(dev, EHCI_BAR_INDEX) & ~0x0f); |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 109 | #endif |
| 110 | return base + HC_LENGTH(read32(base)); |
| 111 | } |