1 | /* FPGA.c -- Bridge for second and subsequent generations |
---|
2 | * |
---|
3 | * COPYRIGHT (c) 1989-2009. |
---|
4 | * On-Line Applications Research Corporation (OAR). |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.org/license/LICENSE. |
---|
9 | */ |
---|
10 | |
---|
11 | #include <bsp.h> |
---|
12 | #include <bsp/irq.h> |
---|
13 | #include <string.h> |
---|
14 | #include <fcntl.h> |
---|
15 | #include <assert.h> |
---|
16 | |
---|
17 | #include <rtems/libio.h> |
---|
18 | #include <rtems/libcsupport.h> |
---|
19 | #include <rtems/bspIo.h> |
---|
20 | |
---|
21 | /* |
---|
22 | * initialize FPGA |
---|
23 | */ |
---|
24 | void initialize_PCI_bridge (void) |
---|
25 | { |
---|
26 | /* Note: Accept DINKs setup of the PCI Bridge and don't |
---|
27 | * change anything. |
---|
28 | */ |
---|
29 | } |
---|
30 | |
---|
31 | void set_irq_mask( |
---|
32 | uint16_t value |
---|
33 | ) |
---|
34 | { |
---|
35 | volatile uint16_t *loc; |
---|
36 | |
---|
37 | loc = (uint16_t*)SCORE603E_FPGA_MASK_DATA; |
---|
38 | |
---|
39 | *loc = value; |
---|
40 | } |
---|
41 | |
---|
42 | uint16_t get_irq_mask( void ) |
---|
43 | { |
---|
44 | volatile uint16_t *loc; |
---|
45 | uint16_t value; |
---|
46 | |
---|
47 | loc = (uint16_t*)SCORE603E_FPGA_MASK_DATA; |
---|
48 | |
---|
49 | value = *loc; |
---|
50 | |
---|
51 | return value; |
---|
52 | } |
---|
53 | |
---|
54 | void mask_irq( |
---|
55 | uint16_t irq_idx |
---|
56 | ) |
---|
57 | { |
---|
58 | uint16_t value; |
---|
59 | uint32_t mask_idx = irq_idx; |
---|
60 | |
---|
61 | value = get_irq_mask(); |
---|
62 | |
---|
63 | #if (HAS_PMC_PSC8) |
---|
64 | switch (irq_idx + Score_IRQ_First ) { |
---|
65 | case SCORE603E_85C30_4_IRQ: |
---|
66 | case SCORE603E_85C30_2_IRQ: |
---|
67 | case SCORE603E_85C30_5_IRQ: |
---|
68 | case SCORE603E_85C30_3_IRQ: |
---|
69 | mask_idx = SCORE603E_PCI_IRQ_0 - Score_IRQ_First; |
---|
70 | break; |
---|
71 | default: |
---|
72 | break; |
---|
73 | } |
---|
74 | #endif |
---|
75 | |
---|
76 | value |= (0x1 << mask_idx); |
---|
77 | set_irq_mask( value ); |
---|
78 | } |
---|
79 | |
---|
80 | void unmask_irq( |
---|
81 | uint16_t irq_idx |
---|
82 | ) |
---|
83 | { |
---|
84 | uint16_t value; |
---|
85 | uint32_t mask_idx = irq_idx; |
---|
86 | |
---|
87 | value = get_irq_mask(); |
---|
88 | |
---|
89 | #if (HAS_PMC_PSC8) |
---|
90 | switch (irq_idx + Score_IRQ_First ) { |
---|
91 | case SCORE603E_85C30_4_IRQ: |
---|
92 | case SCORE603E_85C30_2_IRQ: |
---|
93 | case SCORE603E_85C30_5_IRQ: |
---|
94 | case SCORE603E_85C30_3_IRQ: |
---|
95 | mask_idx = SCORE603E_PCI_IRQ_0 - Score_IRQ_First; |
---|
96 | break; |
---|
97 | default: |
---|
98 | break; |
---|
99 | } |
---|
100 | #endif |
---|
101 | |
---|
102 | value &= (~(0x1 << mask_idx)); |
---|
103 | set_irq_mask( value ); |
---|
104 | } |
---|
105 | |
---|
106 | void init_irq_data_register(void) |
---|
107 | { |
---|
108 | uint32_t index; |
---|
109 | uint32_t i; |
---|
110 | |
---|
111 | set_irq_mask( 0xffff ); |
---|
112 | |
---|
113 | /* |
---|
114 | * Clear any existing interupts from the vector data register. |
---|
115 | */ |
---|
116 | for (i=0; i<20; i++) { |
---|
117 | index = (*SCORE603E_FPGA_VECT_DATA); |
---|
118 | if ( (index&0x10) != 0x10 ) |
---|
119 | break; |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | uint16_t read_and_clear_PMC_irq( |
---|
124 | uint16_t irq |
---|
125 | ) |
---|
126 | { |
---|
127 | uint16_t status_word = irq; |
---|
128 | |
---|
129 | status_word = (*BSP_PMC_STATUS_ADDRESS); |
---|
130 | |
---|
131 | return status_word; |
---|
132 | } |
---|
133 | |
---|
134 | bool Is_PMC_IRQ( |
---|
135 | uint32_t pmc_irq, |
---|
136 | uint16_t status_word |
---|
137 | ) |
---|
138 | { |
---|
139 | bool result = false; |
---|
140 | |
---|
141 | switch(pmc_irq) { |
---|
142 | case SCORE603E_85C30_4_IRQ: |
---|
143 | result = Is_PMC_85C30_4_IRQ( status_word ) ? true : false; |
---|
144 | break; |
---|
145 | case SCORE603E_85C30_2_IRQ: |
---|
146 | result = Is_PMC_85C30_2_IRQ( status_word ) ? true : false; |
---|
147 | break; |
---|
148 | case SCORE603E_85C30_5_IRQ: |
---|
149 | result = Is_PMC_85C30_5_IRQ( status_word ) ? true : false; |
---|
150 | break; |
---|
151 | case SCORE603E_85C30_3_IRQ: |
---|
152 | result = Is_PMC_85C30_3_IRQ( status_word ) ? true : false; |
---|
153 | break; |
---|
154 | default: |
---|
155 | assert( 0 ); |
---|
156 | break; |
---|
157 | } |
---|
158 | |
---|
159 | return result; |
---|
160 | } |
---|
161 | |
---|
162 | uint16_t read_and_clear_irq(void) |
---|
163 | { |
---|
164 | uint16_t irq; |
---|
165 | |
---|
166 | |
---|
167 | irq = (*SCORE603E_FPGA_VECT_DATA); |
---|
168 | Processor_Synchronize(); |
---|
169 | if ((irq & 0xffff0) != 0x10) { |
---|
170 | printk( "read_and_clear_irq:: ERROR==>no irq data 0x%x\n", irq); |
---|
171 | return (irq | 0x80); |
---|
172 | } |
---|
173 | |
---|
174 | irq &=0xf; |
---|
175 | irq += Score_IRQ_First; |
---|
176 | return irq; |
---|
177 | } |
---|