OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sh/] [sh4/] [current/] [src/] [pcic.c] - Blame information for rev 817

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      pcic.c
4
//
5
//      HAL PCI controller support
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    jskov
43
// Contributors: jskov
44
// Date:         2001-07-10
45
// Purpose:      Support for SH PCIC module
46
//
47
//####DESCRIPTIONEND####
48
//
49
//===========================================================================
50
 
51
#include <pkgconf/hal.h>
52
 
53
#include <cyg/infra/diag.h>             // diag_printf
54
#include <cyg/hal/plf_io.h>             // PCI definitions
55
#include <cyg/hal/hal_arch.h>           // HAL header
56
#include <cyg/hal/hal_intr.h>           // HAL interrupts/exceptions
57
#include <cyg/hal/hal_io.h>             // IO macros
58
#include <cyg/hal/hal_if.h>
59
#include <cyg/io/pci_hw.h>
60
#include <cyg/io/pci.h>
61
 
62
void
63
cyg_hal_sh_pcic_pci_init(void)
64
{
65
    cyg_uint8  next_bus;
66
    cyg_uint32 tmp;
67
 
68
    static int initialized = 0;
69
    if (initialized) return;
70
    initialized = 1;
71
 
72
    // PCI bus/wait state configs must match those used in the BSC.
73
    HAL_READ_UINT32(CYGARC_REG_BCR1, tmp);
74
    tmp |= 0x40000000;
75
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_BCR1, tmp);
76
    HAL_READ_UINT16(CYGARC_REG_BCR2, tmp);
77
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_BCR2, tmp);
78
    HAL_READ_UINT32(CYGARC_REG_WCR1, tmp);
79
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_WCR1, tmp);
80
    HAL_READ_UINT32(CYGARC_REG_WCR2, tmp);
81
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_WCR2, tmp);
82
    HAL_READ_UINT32(CYGARC_REG_WCR3, tmp);
83
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_WCR3, tmp);
84
    HAL_READ_UINT32(CYGARC_REG_MCR, tmp);
85
    tmp &= ~(CYGARC_REG_MCR_MRSET | CYGARC_REG_MCR_RFSH);
86
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_MCR, tmp);
87
 
88
    // Unmask all PCI related interrupts
89
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_INTM, CYGARC_REG_PCIC_INTM_INIT);
90
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_AINTM, CYGARC_REG_PCIC_AINTM_INIT);
91
 
92
    // Set host PCI config using platform specified parameters.
93
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_COMMAND, 0xfb9000c7);
94
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_CLASS_REV, 0x00000000);
95
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_CACHE_LINE_SIZE, 64<<8);
96
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_BAR_0, CYGARC_REG_PCIC_BAR0_PLF_INIT);
97
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_BAR_1, CYGARC_REG_PCIC_BAR1_PLF_INIT);
98
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_BAR_2, CYGARC_REG_PCIC_BAR2_PLF_INIT);
99
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_SUB_VENDOR, 0x35051054);
100
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_LSR0, CYGARC_REG_PCIC_LSR0_PLF_INIT);
101
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_LSR1, CYGARC_REG_PCIC_LSR1_PLF_INIT);
102
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_LAR0, CYGARC_REG_PCIC_LAR0_PLF_INIT);
103
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_LAR1, CYGARC_REG_PCIC_LAR1_PLF_INIT);
104
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CR, CYGARC_REG_PCIC_CR_INIT);
105
 
106
    // Configure PCI bus.
107
    next_bus = 1;
108
    cyg_pci_configure_bus(0, &next_bus);
109
}
110
 
111
//--------------------------------------------------------------------------
112
// Config space accessor functions
113
cyg_uint32
114
cyg_hal_sh_pcic_pci_cfg_read_dword (cyg_uint32 bus, cyg_uint32 devfn,
115
                                cyg_uint32 offset)
116
{
117
    cyg_uint32 config_data;
118
 
119
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
120
                     CYGARC_REG_PCIC_PAR_ENABLE |
121
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
122
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
123
                     (offset));
124
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_data);
125
 
126
    return config_data;
127
}
128
 
129
cyg_uint16
130
cyg_hal_sh_pcic_pci_cfg_read_word (cyg_uint32 bus, cyg_uint32 devfn,
131
                               cyg_uint32 offset)
132
{
133
    cyg_uint32 config_dword;
134
 
135
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
136
                     CYGARC_REG_PCIC_PAR_ENABLE |
137
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
138
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
139
                     (offset & ~3));
140
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
141
 
142
    return (cyg_uint16)((config_dword >> ((offset & 3) * 8)) & 0xffff);
143
}
144
 
145
cyg_uint8
146
cyg_hal_sh_pcic_pci_cfg_read_byte (cyg_uint32 bus, cyg_uint32 devfn,
147
                               cyg_uint32 offset)
148
{
149
    cyg_uint32 config_dword;
150
 
151
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
152
                     CYGARC_REG_PCIC_PAR_ENABLE |
153
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
154
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
155
                     (offset & ~3));
156
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
157
 
158
    return (cyg_uint8)((config_dword >> ((offset & 3) * 8)) & 0xff);
159
}
160
 
161
void
162
cyg_hal_sh_pcic_pci_cfg_write_dword (cyg_uint32 bus, cyg_uint32 devfn,
163
                                 cyg_uint32 offset, cyg_uint32 data)
164
{
165
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
166
                     CYGARC_REG_PCIC_PAR_ENABLE |
167
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
168
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
169
                     (offset));
170
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PDR, data);
171
}
172
 
173
void
174
cyg_hal_sh_pcic_pci_cfg_write_word (cyg_uint32 bus, cyg_uint32 devfn,
175
                                cyg_uint32 offset, cyg_uint16 data)
176
{
177
    cyg_uint32 config_dword, shift;
178
 
179
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
180
                     CYGARC_REG_PCIC_PAR_ENABLE |
181
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
182
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
183
                     (offset & ~3));
184
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
185
 
186
    shift = (offset & 3) * 8;
187
    config_dword &= ~(0xffff << shift);
188
    config_dword |= (data << shift);
189
 
190
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
191
                     CYGARC_REG_PCIC_PAR_ENABLE |
192
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
193
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
194
                     (offset & ~3));
195
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
196
}
197
 
198
void
199
cyg_hal_sh_pcic_pci_cfg_write_byte (cyg_uint32 bus, cyg_uint32 devfn,
200
                                cyg_uint32 offset, cyg_uint8  data)
201
{
202
    cyg_uint32 config_dword, shift;
203
 
204
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
205
                     CYGARC_REG_PCIC_PAR_ENABLE |
206
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
207
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
208
                     (offset & ~3));
209
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
210
 
211
    shift = (offset & 3) * 8;
212
    config_dword &= ~(0xff << shift);
213
    config_dword |= (data << shift);
214
 
215
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
216
                     CYGARC_REG_PCIC_PAR_ENABLE |
217
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
218
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
219
                     (offset & ~3));
220
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
221
}
222
 
223
//--------------------------------------------------------------------------
224
// IO space accessor functions
225
 
226
void
227
cyg_hal_sh_pcic_pci_io_write_byte (cyg_uint32 addr, cyg_uint8 data)
228
{
229
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
230
    HAL_WRITE_UINT8(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
231
                    data);
232
}
233
 
234
void
235
cyg_hal_sh_pcic_pci_io_write_word (cyg_uint32 addr, cyg_uint16 data)
236
{
237
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
238
    HAL_WRITE_UINT16(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
239
                     data);
240
}
241
 
242
void
243
cyg_hal_sh_pcic_pci_io_write_dword (cyg_uint32 addr, cyg_uint32 data)
244
{
245
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
246
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
247
                     data);
248
}
249
 
250
cyg_uint8
251
cyg_hal_sh_pcic_pci_io_read_byte (cyg_uint32 addr)
252
{
253
    cyg_uint8 data;
254
 
255
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
256
    HAL_READ_UINT8(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
257
                   data);
258
    return data;
259
}
260
 
261
cyg_uint16
262
cyg_hal_sh_pcic_pci_io_read_word (cyg_uint32 addr)
263
{
264
    cyg_uint16 data;
265
 
266
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
267
    HAL_READ_UINT16(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
268
                    data);
269
    return data;
270
}
271
 
272
cyg_uint32
273
cyg_hal_sh_pcic_pci_io_read_dword (cyg_uint32 addr)
274
{
275
    cyg_uint32 data;
276
 
277
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
278
    HAL_READ_UINT32(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
279
                    data);
280
    return data;
281
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.