[e2cc9a0] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Jakub Jermar
|
---|
[e2cc9a0] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup sparc64
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief PCI driver.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <arch/drivers/pci.h>
|
---|
| 38 | #include <genarch/ofw/ofw_tree.h>
|
---|
[e731b0d] | 39 | #include <genarch/ofw/upa.h>
|
---|
[e2cc9a0] | 40 | #include <arch/trap/interrupt.h>
|
---|
[d4673296] | 41 | #include <mm/km.h>
|
---|
[e2cc9a0] | 42 | #include <mm/slab.h>
|
---|
[d99c1d2] | 43 | #include <typedefs.h>
|
---|
[e2cc9a0] | 44 | #include <debug.h>
|
---|
| 45 | #include <print.h>
|
---|
[19f857a] | 46 | #include <str.h>
|
---|
[e2cc9a0] | 47 | #include <arch/asm.h>
|
---|
[42742c5a] | 48 | #include <sysinfo/sysinfo.h>
|
---|
[e2cc9a0] | 49 |
|
---|
[dfd77382] | 50 | #define SABRE_INTERNAL_REG 0
|
---|
[19f857a] | 51 | #define PSYCHO_INTERNAL_REG 2
|
---|
[e2cc9a0] | 52 |
|
---|
[dfd77382] | 53 | #define OBIO_IMR_BASE 0x200
|
---|
| 54 | #define OBIO_IMR(ino) (OBIO_IMR_BASE + ((ino) & INO_MASK))
|
---|
[e2cc9a0] | 55 |
|
---|
[dfd77382] | 56 | #define OBIO_CIR_BASE 0x300
|
---|
| 57 | #define OBIO_CIR(ino) (OBIO_CIR_BASE + ((ino) & INO_MASK))
|
---|
[d4f184f] | 58 |
|
---|
[8d2760f] | 59 | static void obio_enable_interrupt(pci_t *, int);
|
---|
| 60 | static void obio_clear_interrupt(pci_t *, int);
|
---|
[d4f184f] | 61 |
|
---|
[8d2760f] | 62 | static pci_t *pci_sabre_init(ofw_tree_node_t *);
|
---|
| 63 | static pci_t *pci_psycho_init(ofw_tree_node_t *);
|
---|
[d4f184f] | 64 |
|
---|
[e2cc9a0] | 65 | /** PCI operations for Sabre model. */
|
---|
| 66 | static pci_operations_t pci_sabre_ops = {
|
---|
[dfd77382] | 67 | .enable_interrupt = obio_enable_interrupt,
|
---|
| 68 | .clear_interrupt = obio_clear_interrupt
|
---|
[e2cc9a0] | 69 | };
|
---|
[d4f184f] | 70 | /** PCI operations for Psycho model. */
|
---|
| 71 | static pci_operations_t pci_psycho_ops = {
|
---|
[dfd77382] | 72 | .enable_interrupt = obio_enable_interrupt,
|
---|
| 73 | .clear_interrupt = obio_clear_interrupt
|
---|
[d4f184f] | 74 | };
|
---|
[e2cc9a0] | 75 |
|
---|
[d4f184f] | 76 | /** Initialize PCI controller (model Sabre).
|
---|
| 77 | *
|
---|
[dfd77382] | 78 | * @param node OpenFirmware device tree node of the Sabre.
|
---|
[d4f184f] | 79 | *
|
---|
[dfd77382] | 80 | * @return Address of the initialized PCI structure.
|
---|
[d4f184f] | 81 | */
|
---|
[e2cc9a0] | 82 | pci_t *pci_sabre_init(ofw_tree_node_t *node)
|
---|
| 83 | {
|
---|
| 84 | pci_t *pci;
|
---|
| 85 | ofw_tree_property_t *prop;
|
---|
| 86 |
|
---|
| 87 | /*
|
---|
| 88 | * Get registers.
|
---|
| 89 | */
|
---|
| 90 | prop = ofw_tree_getprop(node, "reg");
|
---|
| 91 | if (!prop || !prop->value)
|
---|
| 92 | return NULL;
|
---|
| 93 |
|
---|
| 94 | ofw_upa_reg_t *reg = prop->value;
|
---|
[98000fb] | 95 | size_t regs = prop->size / sizeof(ofw_upa_reg_t);
|
---|
[e2cc9a0] | 96 |
|
---|
[dfd77382] | 97 | if (regs < SABRE_INTERNAL_REG + 1)
|
---|
[e2cc9a0] | 98 | return NULL;
|
---|
| 99 |
|
---|
| 100 | uintptr_t paddr;
|
---|
[dfd77382] | 101 | if (!ofw_upa_apply_ranges(node->parent, ®[SABRE_INTERNAL_REG],
|
---|
| 102 | &paddr))
|
---|
[e2cc9a0] | 103 | return NULL;
|
---|
| 104 |
|
---|
| 105 | pci = (pci_t *) malloc(sizeof(pci_t), FRAME_ATOMIC);
|
---|
| 106 | if (!pci)
|
---|
| 107 | return NULL;
|
---|
| 108 |
|
---|
| 109 | pci->model = PCI_SABRE;
|
---|
| 110 | pci->op = &pci_sabre_ops;
|
---|
[adec5b45] | 111 | pci->reg = (uint64_t *) km_map(paddr, reg[SABRE_INTERNAL_REG].size,
|
---|
| 112 | PAGE_WRITE | PAGE_NOT_CACHEABLE);
|
---|
[e2cc9a0] | 113 |
|
---|
[42742c5a] | 114 | /*
|
---|
| 115 | * Set sysinfo data needed by the uspace OBIO driver.
|
---|
| 116 | */
|
---|
| 117 | sysinfo_set_item_val("obio.base.physical", NULL, paddr);
|
---|
| 118 | sysinfo_set_item_val("kbd.cir.obio", NULL, 1);
|
---|
| 119 |
|
---|
[e2cc9a0] | 120 | return pci;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[d4f184f] | 123 |
|
---|
| 124 | /** Initialize the Psycho PCI controller.
|
---|
| 125 | *
|
---|
[dfd77382] | 126 | * @param node OpenFirmware device tree node of the Psycho.
|
---|
[d4f184f] | 127 | *
|
---|
[dfd77382] | 128 | * @return Address of the initialized PCI structure.
|
---|
[d4f184f] | 129 | */
|
---|
| 130 | pci_t *pci_psycho_init(ofw_tree_node_t *node)
|
---|
| 131 | {
|
---|
| 132 | pci_t *pci;
|
---|
| 133 | ofw_tree_property_t *prop;
|
---|
| 134 |
|
---|
| 135 | /*
|
---|
| 136 | * Get registers.
|
---|
| 137 | */
|
---|
| 138 | prop = ofw_tree_getprop(node, "reg");
|
---|
| 139 | if (!prop || !prop->value)
|
---|
| 140 | return NULL;
|
---|
| 141 |
|
---|
| 142 | ofw_upa_reg_t *reg = prop->value;
|
---|
[98000fb] | 143 | size_t regs = prop->size / sizeof(ofw_upa_reg_t);
|
---|
[d4f184f] | 144 |
|
---|
[dfd77382] | 145 | if (regs < PSYCHO_INTERNAL_REG + 1)
|
---|
[d4f184f] | 146 | return NULL;
|
---|
| 147 |
|
---|
| 148 | uintptr_t paddr;
|
---|
[dfd77382] | 149 | if (!ofw_upa_apply_ranges(node->parent, ®[PSYCHO_INTERNAL_REG],
|
---|
| 150 | &paddr))
|
---|
[d4f184f] | 151 | return NULL;
|
---|
| 152 |
|
---|
| 153 | pci = (pci_t *) malloc(sizeof(pci_t), FRAME_ATOMIC);
|
---|
| 154 | if (!pci)
|
---|
| 155 | return NULL;
|
---|
| 156 |
|
---|
| 157 | pci->model = PCI_PSYCHO;
|
---|
| 158 | pci->op = &pci_psycho_ops;
|
---|
[adec5b45] | 159 | pci->reg = (uint64_t *) km_map(paddr, reg[PSYCHO_INTERNAL_REG].size,
|
---|
| 160 | PAGE_WRITE | PAGE_NOT_CACHEABLE);
|
---|
[d4f184f] | 161 |
|
---|
[42742c5a] | 162 | /*
|
---|
| 163 | * Set sysinfo data needed by the uspace OBIO driver.
|
---|
| 164 | */
|
---|
| 165 | sysinfo_set_item_val("obio.base.physical", NULL, paddr);
|
---|
| 166 | sysinfo_set_item_val("kbd.cir.obio", NULL, 1);
|
---|
| 167 |
|
---|
[d4f184f] | 168 | return pci;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[dfd77382] | 171 | void obio_enable_interrupt(pci_t *pci, int inr)
|
---|
[d4f184f] | 172 | {
|
---|
[dfd77382] | 173 | pci->reg[OBIO_IMR(inr & INO_MASK)] |= IMAP_V_MASK;
|
---|
[d4f184f] | 174 | }
|
---|
| 175 |
|
---|
[dfd77382] | 176 | void obio_clear_interrupt(pci_t *pci, int inr)
|
---|
[d4f184f] | 177 | {
|
---|
[dfd77382] | 178 | pci->reg[OBIO_CIR(inr & INO_MASK)] = 0; /* set IDLE */
|
---|
[d4f184f] | 179 | }
|
---|
| 180 |
|
---|
[e2cc9a0] | 181 | /** Initialize PCI controller. */
|
---|
| 182 | pci_t *pci_init(ofw_tree_node_t *node)
|
---|
| 183 | {
|
---|
| 184 | ofw_tree_property_t *prop;
|
---|
| 185 |
|
---|
| 186 | /*
|
---|
| 187 | * First, verify this is a PCI node.
|
---|
| 188 | */
|
---|
[b60c582] | 189 | ASSERT(str_cmp(ofw_tree_node_name(node), "pci") == 0);
|
---|
[e2cc9a0] | 190 |
|
---|
| 191 | /*
|
---|
| 192 | * Determine PCI controller model.
|
---|
| 193 | */
|
---|
| 194 | prop = ofw_tree_getprop(node, "model");
|
---|
| 195 | if (!prop || !prop->value)
|
---|
| 196 | return NULL;
|
---|
| 197 |
|
---|
[b60c582] | 198 | if (str_cmp(prop->value, "SUNW,sabre") == 0) {
|
---|
[e2cc9a0] | 199 | /*
|
---|
| 200 | * PCI controller Sabre.
|
---|
| 201 | * This model is found on UltraSPARC IIi based machines.
|
---|
| 202 | */
|
---|
| 203 | return pci_sabre_init(node);
|
---|
[b60c582] | 204 | } else if (str_cmp(prop->value, "SUNW,psycho") == 0) {
|
---|
[d4f184f] | 205 | /*
|
---|
| 206 | * PCI controller Psycho.
|
---|
| 207 | * Used on UltraSPARC II based processors, for instance,
|
---|
| 208 | * on Ultra 60.
|
---|
| 209 | */
|
---|
| 210 | return pci_psycho_init(node);
|
---|
[e2cc9a0] | 211 | } else {
|
---|
| 212 | /*
|
---|
| 213 | * Unsupported model.
|
---|
| 214 | */
|
---|
[7e752b2] | 215 | printf("Unsupported PCI controller model (%s).\n",
|
---|
| 216 | (char *) prop->value);
|
---|
[e2cc9a0] | 217 | }
|
---|
| 218 |
|
---|
| 219 | return NULL;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | void pci_enable_interrupt(pci_t *pci, int inr)
|
---|
| 223 | {
|
---|
| 224 | ASSERT(pci->op && pci->op->enable_interrupt);
|
---|
| 225 | pci->op->enable_interrupt(pci, inr);
|
---|
| 226 | }
|
---|
| 227 |
|
---|
[8d2760f] | 228 | void pci_clear_interrupt(void *pcip, int inr)
|
---|
[e2cc9a0] | 229 | {
|
---|
[8d2760f] | 230 | pci_t *pci = (pci_t *)pcip;
|
---|
| 231 |
|
---|
[e2cc9a0] | 232 | ASSERT(pci->op && pci->op->clear_interrupt);
|
---|
| 233 | pci->op->clear_interrupt(pci, inr);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | /** @}
|
---|
| 237 | */
|
---|