Rev 3647 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3647 | jermar | 1 | /* |
2 | * Copyright (c) 2008 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 sparc64 |
||
30 | * @{ |
||
31 | */ |
||
32 | /** |
||
33 | * @file |
||
34 | * @brief Driver for the UPA to PCI bridge (Psycho). |
||
35 | */ |
||
36 | |||
37 | #include <arch/drivers/psycho.h> |
||
38 | #include <arch/trap/interrupt.h> |
||
39 | #include <mm/page.h> |
||
40 | #include <mm/slab.h> |
||
41 | #include <arch/types.h> |
||
42 | #include <genarch/ofw/ofw_tree.h> |
||
3649 | jermar | 43 | #include <byteorder.h> |
3647 | jermar | 44 | |
3649 | jermar | 45 | #define PSYCHO_INTERNAL_REG 2 |
3647 | jermar | 46 | |
3649 | jermar | 47 | #define PSYCHO_OBIO_IMR_BASE (0x1000 / sizeof(uint64_t)) |
48 | #define PSYCHO_OBIO_IMR(ino) (PSYCHO_OBIO_IMR_BASE + ((ino) & INO_MASK)) |
||
49 | |||
50 | #define PSYCHO_OBIO_CIR_BASE (0x1800 / sizeof(uint64_t)) |
||
51 | #define PSYCHO_OBIO_CIR(ino) (PSYCHO_OBIO_CIR_BASE + ((ino) & INO_MASK)) |
||
52 | |||
3647 | jermar | 53 | psycho_t *psycho_a = NULL; |
54 | psycho_t *psycho_b = NULL; |
||
55 | |||
56 | psycho_t *psycho_init(ofw_tree_node_t *node) |
||
57 | { |
||
58 | psycho_t *psycho; |
||
59 | ofw_tree_property_t *prop; |
||
60 | |||
61 | prop = ofw_tree_getprop(node, "reg"); |
||
62 | |||
63 | if (!prop || !prop->value) |
||
64 | return NULL; |
||
3649 | jermar | 65 | |
66 | count_t regs = prop->size / sizeof(ofw_upa_reg_t); |
||
67 | if (regs < PSYCHO_INTERNAL_REG + 1) |
||
68 | return NULL; |
||
3647 | jermar | 69 | |
3649 | jermar | 70 | ofw_upa_reg_t *reg = |
71 | &((ofw_upa_reg_t *) prop->value)[PSYCHO_INTERNAL_REG]; |
||
3647 | jermar | 72 | |
73 | uintptr_t paddr; |
||
74 | if (!ofw_upa_apply_ranges(node->parent, reg, &paddr)) |
||
75 | return NULL; |
||
76 | |||
77 | psycho = (psycho_t *) malloc(sizeof(psycho_t), FRAME_ATOMIC); |
||
78 | if (!psycho) |
||
79 | return NULL; |
||
80 | |||
81 | psycho->regs = (uint64_t *) hw_map(paddr, reg->size); |
||
82 | |||
83 | return psycho; |
||
84 | } |
||
85 | |||
86 | void psycho_enable_interrupt(psycho_t *psycho, int inr) |
||
87 | { |
||
3649 | jermar | 88 | int ino = inr & ~IGN_MASK; |
89 | uint64_t imr = psycho->regs[PSYCHO_OBIO_IMR(ino)]; |
||
90 | imr |= host2uint64_t_le(IMAP_V_MASK); |
||
91 | psycho->regs[PSYCHO_OBIO_IMR(ino)] = imr; |
||
3647 | jermar | 92 | } |
93 | |||
94 | void psycho_clear_interrupt(psycho_t *psycho, int inr) |
||
95 | { |
||
3649 | jermar | 96 | int ino = inr & ~IGN_MASK; |
97 | uint64_t idle = host2uint64_t_le(0); |
||
98 | psycho->regs[PSYCHO_OBIO_CIR(ino)] = idle; |
||
3647 | jermar | 99 | } |
100 | |||
101 | /** @} |
||
102 | */ |