1 //==========================================================================
5 // HAL platform miscellaneous functions
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: jskov
46 // Purpose: HAL miscellaneous functions
47 // Description: This file contains miscellaneous functions provided by the
50 //####DESCRIPTIONEND####
52 //==========================================================================
54 #include <pkgconf/hal.h>
56 #include <cyg/infra/cyg_type.h> // Base types
58 #include <cyg/hal/hal_arch.h> // architectural definitions
59 #include <cyg/hal/hal_intr.h> // Interrupt handling
61 #include <cyg/hal/hal_if.h> // Calling interface definitions
63 #if defined(CYGPKG_IO_PCI)
64 #include <cyg/io/pci_hw.h>
65 #include <cyg/io/pci.h>
68 //--------------------------------------------------------------------------
70 void hal_platform_init(void)
74 // FIXME: Set up Galileo interrupt controller?
76 // Unmask vectors which are entry points for interrupt controllers
77 // HAL_INTERRUPT_UNMASK(CYGNUM_HAL_INTERRUPT_21555);
78 // HAL_INTERRUPT_UNMASK(CYGNUM_HAL_INTERRUPT_GALILEO);
81 //--------------------------------------------------------------------------
83 #if defined(CYGPKG_IO_PCI)
85 static int __check_bar(cyg_uint32 addr, cyg_uint32 size)
89 for (n = 0; n <= 31; n++)
90 if (size == (1 << n)) {
91 /* Check that address is naturally aligned */
92 if (addr != (addr & ~(size-1)))
100 // One-time PCI initialization.
102 void cyg_hal_plf_pci_init(void)
104 cyg_uint32 bar_ena, start10, start32, end, size;
107 // Program PCI window in CPU address space and CPU->PCI remap
108 HAL_GALILEO_PUTREG(HAL_GALILEO_PCIMEM0_LD_OFFSET,
109 HAL_OCELOT_PCI_MEM0_BASE >> HAL_GALILEO_CPU_DECODE_SHIFT);
110 HAL_GALILEO_PUTREG(HAL_GALILEO_PCIMEM0_HD_OFFSET,
111 (HAL_OCELOT_PCI_MEM0_BASE+HAL_OCELOT_PCI_MEM0_SIZE-1) >> HAL_GALILEO_CPU_DECODE_SHIFT);
113 HAL_GALILEO_PUTREG(HAL_GALILEO_PCIMEM1_LD_OFFSET,
114 HAL_OCELOT_PCI_MEM1_BASE >> HAL_GALILEO_CPU_DECODE_SHIFT);
115 HAL_GALILEO_PUTREG(HAL_GALILEO_PCIMEM1_HD_OFFSET,
116 (HAL_OCELOT_PCI_MEM1_BASE+HAL_OCELOT_PCI_MEM1_SIZE-1) >> HAL_GALILEO_CPU_DECODE_SHIFT);
118 HAL_GALILEO_PUTREG(HAL_GALILEO_PCIIO_LD_OFFSET,
119 HAL_OCELOT_PCI_IO_BASE >> HAL_GALILEO_CPU_DECODE_SHIFT);
120 HAL_GALILEO_PUTREG(HAL_GALILEO_PCIIO_HD_OFFSET,
121 (HAL_OCELOT_PCI_IO_BASE+HAL_OCELOT_PCI_IO_SIZE-1) >> HAL_GALILEO_CPU_DECODE_SHIFT);
123 // Setup for bus mastering
124 cyg_hal_plf_pci_cfg_write_dword(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
126 CYG_PCI_CFG_COMMAND_IO |
127 CYG_PCI_CFG_COMMAND_MEMORY |
128 CYG_PCI_CFG_COMMAND_MASTER |
129 CYG_PCI_CFG_COMMAND_PARITY |
130 CYG_PCI_CFG_COMMAND_SERR);
132 // Setup latency timer field
133 cyg_hal_plf_pci_cfg_write_byte(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
134 CYG_PCI_CFG_LATENCY_TIMER, 6);
139 // Allow PCI bus to access local memory
140 // Check for active SCS10
141 start10 = HAL_GALILEO_GETREG(HAL_GALILEO_SCS10_LD_OFFSET) << HAL_GALILEO_CPU_DECODE_SHIFT;
142 end = ((HAL_GALILEO_GETREG(HAL_GALILEO_SCS10_HD_OFFSET) & 0x7f) + 1) << HAL_GALILEO_CPU_DECODE_SHIFT;
144 if ((size = __check_bar(start10, end - start10)) != 0) {
146 HAL_GALILEO_PUTREG(HAL_GALILEO_PCI0_SCS10_SIZE_OFFSET, size);
147 bar_ena &= ~HAL_GALILEO_BAR_ENA_SCS10;
151 // Check for active SCS32
152 start32 = HAL_GALILEO_GETREG(HAL_GALILEO_SCS32_LD_OFFSET) << HAL_GALILEO_CPU_DECODE_SHIFT;
153 end = ((HAL_GALILEO_GETREG(HAL_GALILEO_SCS32_HD_OFFSET) & 0x7f) + 1) << HAL_GALILEO_CPU_DECODE_SHIFT;
155 if ((size = __check_bar(start32, end - start32)) != 0) {
157 HAL_GALILEO_PUTREG(HAL_GALILEO_PCI0_SCS32_SIZE_OFFSET, size);
158 bar_ena &= ~HAL_GALILEO_BAR_ENA_SCS32;
162 bar_ena &= ~HAL_GALILEO_BAR_ENA_SCS10;
164 HAL_GALILEO_PUTREG(HAL_GALILEO_BAR_ENA_OFFSET, bar_ena);
166 cyg_hal_plf_pci_cfg_write_dword(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
167 CYG_PCI_CFG_BAR_0, 0xffffffff);
169 end = cyg_hal_plf_pci_cfg_read_dword(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
172 cyg_hal_plf_pci_cfg_write_dword(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
173 CYG_PCI_CFG_BAR_0, start10);
176 cyg_hal_plf_pci_cfg_write_dword(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
177 CYG_PCI_CFG_BAR_1, 0xffffffff);
179 end = cyg_hal_plf_pci_cfg_read_dword(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
182 cyg_hal_plf_pci_cfg_write_dword(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
183 CYG_PCI_CFG_BAR_1, start32);
185 // Configure PCI bus.
187 cyg_pci_configure_bus(0, &next_bus);
191 // Check for configuration error.
192 static int pci_config_errcheck(void)
196 // Check for master or target abort
197 irq = HAL_GALILEO_GETREG(HAL_GALILEO_IRQ_CAUSE_OFFSET);
199 if (irq & (HAL_GALILEO_IRQCAUSE_MASABT | HAL_GALILEO_IRQCAUSE_TARABT)) {
200 // Error. Clear bits.
201 HAL_GALILEO_PUTREG(HAL_GALILEO_IRQ_CAUSE_OFFSET,
202 ~(HAL_GALILEO_IRQCAUSE_MASABT | HAL_GALILEO_IRQCAUSE_TARABT));
208 cyg_uint32 cyg_hal_plf_pci_cfg_read_dword (cyg_uint32 bus,
212 cyg_uint32 config_dword;
214 HAL_GALILEO_PUTREG(HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET,
215 HAL_GALILEO_PCI0_CONFIG_ADDR_ENABLE |
216 (bus << 16) | (devfn << 8) | offset);
218 HAL_GALILEO_GETPCI(bus, devfn,
219 HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET, config_dword);
221 if (pci_config_errcheck())
226 cyg_uint16 cyg_hal_plf_pci_cfg_read_word (cyg_uint32 bus,
230 cyg_uint32 config_dword;
231 cyg_uint16 config_word;
233 HAL_GALILEO_PUTREG(HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET,
234 HAL_GALILEO_PCI0_CONFIG_ADDR_ENABLE |
235 (bus << 16) | (devfn << 8) | (offset & ~3));
237 HAL_GALILEO_GETPCI(bus, devfn,
238 HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET, config_dword);
239 config_word = (cyg_uint16)((config_dword >> ((offset & 3) * 8)) & 0xffff);
241 if (pci_config_errcheck())
247 cyg_uint8 cyg_hal_plf_pci_cfg_read_byte (cyg_uint32 bus,
251 cyg_uint32 config_dword;
252 cyg_uint8 config_byte;
254 HAL_GALILEO_PUTREG(HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET,
255 HAL_GALILEO_PCI0_CONFIG_ADDR_ENABLE |
256 (bus << 16) | (devfn << 8) | (offset & ~3));
258 HAL_GALILEO_GETPCI(bus, devfn,
259 HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET, config_dword);
260 config_byte = (cyg_uint8)((config_dword >> ((offset & 3) * 8)) & 0xff);
262 if (pci_config_errcheck())
268 void cyg_hal_plf_pci_cfg_write_dword (cyg_uint32 bus,
273 HAL_GALILEO_PUTREG(HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET,
274 HAL_GALILEO_PCI0_CONFIG_ADDR_ENABLE |
275 (bus << 16) | (devfn << 8) | offset);
277 HAL_GALILEO_PUTPCI(bus, devfn,
278 HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET, data);
280 (void)pci_config_errcheck();
283 void cyg_hal_plf_pci_cfg_write_word (cyg_uint32 bus,
288 cyg_uint32 config_dword, shift;
290 HAL_GALILEO_PUTREG(HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET,
291 HAL_GALILEO_PCI0_CONFIG_ADDR_ENABLE |
292 (bus << 16) | (devfn << 8) | (offset & ~3));
295 HAL_GALILEO_GETPCI(bus, devfn,
296 HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET, config_dword);
297 if (pci_config_errcheck())
300 shift = (offset & 3) * 8;
301 config_dword &= ~(0xffff << shift);
302 config_dword |= (data << shift);
304 HAL_GALILEO_PUTPCI(bus, devfn,
305 HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET, config_dword);
307 (void)pci_config_errcheck();
310 void cyg_hal_plf_pci_cfg_write_byte (cyg_uint32 bus,
315 cyg_uint32 config_dword, shift;
317 HAL_GALILEO_PUTREG(HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET,
318 HAL_GALILEO_PCI0_CONFIG_ADDR_ENABLE |
319 (bus << 16) | (devfn << 8) | (offset & ~3));
321 HAL_GALILEO_GETPCI(bus, devfn,
322 HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET, config_dword);
323 if (pci_config_errcheck())
326 shift = (offset & 3) * 8;
327 config_dword &= ~(0xff << shift);
328 config_dword |= (data << shift);
330 HAL_GALILEO_PUTPCI(bus, devfn,
331 HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET, config_dword);
333 (void)pci_config_errcheck();
336 #endif // CYGPKG_IO_PCI
338 //--------------------------------------------------------------------------