source: mainline/kernel/genarch/src/ofw/ebus.c@ 202f57b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 202f57b was 19f857a, checked in by Jiri Svoboda <jiri@…>, 15 years ago

Rename string.h to str.h to avoid header conflict with standard C string.h.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2006 Jakub Jermar
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 ofw
30 * @{
31 */
32/**
33 * @file
34 * @brief EBUS 'reg' and 'ranges' properties handling.
35 *
36 */
37
38#include <genarch/ofw/ofw_tree.h>
39#include <genarch/ofw/ebus.h>
40#include <genarch/ofw/pci.h>
41#include <arch/memstr.h>
42#include <str.h>
43#include <panic.h>
44#include <debug.h>
45#include <macros.h>
46
47/** Apply EBUS ranges to EBUS register. */
48bool
49ofw_ebus_apply_ranges(ofw_tree_node_t *node, ofw_ebus_reg_t *reg, uintptr_t *pa)
50{
51 ofw_tree_property_t *prop;
52 ofw_ebus_range_t *range;
53 size_t ranges;
54
55 prop = ofw_tree_getprop(node, "ranges");
56 if (!prop)
57 return false;
58
59 ranges = prop->size / sizeof(ofw_ebus_range_t);
60 range = prop->value;
61
62 unsigned int i;
63
64 for (i = 0; i < ranges; i++) {
65 if (reg->space != range[i].child_space)
66 continue;
67 if (overlaps(reg->addr, reg->size, range[i].child_base,
68 range[i].size)) {
69 ofw_pci_reg_t pci_reg;
70
71 pci_reg.space = range[i].parent_space;
72 pci_reg.addr = range[i].parent_base +
73 (reg->addr - range[i].child_base);
74 pci_reg.size = reg->size;
75
76 return ofw_pci_apply_ranges(node->parent, &pci_reg, pa);
77 }
78 }
79
80 return false;
81}
82
83bool
84ofw_ebus_map_interrupt(ofw_tree_node_t *node, ofw_ebus_reg_t *reg,
85 uint32_t interrupt, int *inr, cir_t *cir, void **cir_arg)
86{
87 ofw_tree_property_t *prop;
88 ofw_tree_node_t *controller;
89
90 prop = ofw_tree_getprop(node, "interrupt-map");
91 if (!prop || !prop->value)
92 return false;
93
94 ofw_ebus_intr_map_t *intr_map = prop->value;
95 size_t count = prop->size / sizeof(ofw_ebus_intr_map_t);
96
97 ASSERT(count);
98
99 prop = ofw_tree_getprop(node, "interrupt-map-mask");
100 if (!prop || !prop->value)
101 return false;
102
103 ofw_ebus_intr_mask_t *intr_mask = prop->value;
104
105 ASSERT(prop->size == sizeof(ofw_ebus_intr_mask_t));
106
107 uint32_t space = reg->space & intr_mask->space_mask;
108 uint32_t addr = reg->addr & intr_mask->addr_mask;
109 uint32_t intr = interrupt & intr_mask->intr_mask;
110
111 unsigned int i;
112 for (i = 0; i < count; i++) {
113 if ((intr_map[i].space == space) &&
114 (intr_map[i].addr == addr) && (intr_map[i].intr == intr))
115 goto found;
116 }
117 return false;
118
119found:
120 /*
121 * We found the device that functions as an interrupt controller
122 * for the interrupt. We also found partial mapping from interrupt to
123 * INO.
124 */
125
126 controller = ofw_tree_find_node_by_handle(ofw_tree_lookup("/"),
127 intr_map[i].controller_handle);
128 if (!controller)
129 return false;
130
131 if (str_cmp(ofw_tree_node_name(controller), "pci") != 0) {
132 /*
133 * This is not a PCI node.
134 */
135 return false;
136 }
137
138 /*
139 * Let the PCI do the next step in mapping the interrupt.
140 */
141 if (!ofw_pci_map_interrupt(controller, NULL, intr_map[i].controller_ino,
142 inr, cir, cir_arg))
143 return false;
144
145 return true;
146}
147
148/** @}
149 */
Note: See TracBrowser for help on using the repository browser.