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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [sh/] [sh4/] [v2_0/] [src/] [pcic.c] - Blame information for rev 27

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
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 Red Hat, 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 version.
16
//
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
20
// for more details.
21
//
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.
25
//
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.
32
//
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.
35
//
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####
42
//
43
// Author(s):    jskov
44
// Contributors: jskov
45
// Date:         2001-07-10
46
// Purpose:      Support for SH PCIC module
47
//
48
//####DESCRIPTIONEND####
49
//
50
//===========================================================================
51
 
52
#include <pkgconf/hal.h>
53
 
54
#include <cyg/infra/diag.h>             // diag_printf
55
#include <cyg/hal/plf_io.h>             // PCI definitions
56
#include <cyg/hal/hal_arch.h>           // HAL header
57
#include <cyg/hal/hal_intr.h>           // HAL interrupts/exceptions
58
#include <cyg/hal/hal_io.h>             // IO macros
59
#include <cyg/hal/hal_if.h>
60
#include <cyg/io/pci_hw.h>
61
#include <cyg/io/pci.h>
62
 
63
void
64
cyg_hal_sh_pcic_pci_init(void)
65
{
66
    cyg_uint8  next_bus;
67
    cyg_uint32 tmp;
68
 
69
    static int initialized = 0;
70
    if (initialized) return;
71
    initialized = 1;
72
 
73
    // PCI bus/wait state configs must match those used in the BSC.
74
    HAL_READ_UINT32(CYGARC_REG_BCR1, tmp);
75
    tmp |= 0x40000000;
76
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_BCR1, tmp);
77
    HAL_READ_UINT16(CYGARC_REG_BCR2, tmp);
78
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_BCR2, tmp);
79
    HAL_READ_UINT32(CYGARC_REG_WCR1, tmp);
80
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_WCR1, tmp);
81
    HAL_READ_UINT32(CYGARC_REG_WCR2, tmp);
82
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_WCR2, tmp);
83
    HAL_READ_UINT32(CYGARC_REG_WCR3, tmp);
84
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_WCR3, tmp);
85
    HAL_READ_UINT32(CYGARC_REG_MCR, tmp);
86
    tmp &= ~(CYGARC_REG_MCR_MRSET | CYGARC_REG_MCR_RFSH);
87
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_MCR, tmp);
88
 
89
    // Unmask all PCI related interrupts
90
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_INTM, CYGARC_REG_PCIC_INTM_INIT);
91
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_AINTM, CYGARC_REG_PCIC_AINTM_INIT);
92
 
93
    // Set host PCI config using platform specified parameters.
94
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_COMMAND, 0xfb9000c7);
95
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_CLASS_REV, 0x00000000);
96
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_CACHE_LINE_SIZE, 64<<8);
97
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_BAR_0, CYGARC_REG_PCIC_BAR0_PLF_INIT);
98
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_BAR_1, CYGARC_REG_PCIC_BAR1_PLF_INIT);
99
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_BAR_2, CYGARC_REG_PCIC_BAR2_PLF_INIT);
100
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CFG+CYG_PCI_CFG_SUB_VENDOR, 0x35051054);
101
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_LSR0, CYGARC_REG_PCIC_LSR0_PLF_INIT);
102
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_LSR1, CYGARC_REG_PCIC_LSR1_PLF_INIT);
103
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_LAR0, CYGARC_REG_PCIC_LAR0_PLF_INIT);
104
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_LAR1, CYGARC_REG_PCIC_LAR1_PLF_INIT);
105
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_CR, CYGARC_REG_PCIC_CR_INIT);
106
 
107
    // Configure PCI bus.
108
    next_bus = 1;
109
    cyg_pci_configure_bus(0, &next_bus);
110
}
111
 
112
//--------------------------------------------------------------------------
113
// Config space accessor functions
114
cyg_uint32
115
cyg_hal_sh_pcic_pci_cfg_read_dword (cyg_uint32 bus, cyg_uint32 devfn,
116
                                cyg_uint32 offset)
117
{
118
    cyg_uint32 config_data;
119
 
120
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
121
                     CYGARC_REG_PCIC_PAR_ENABLE |
122
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
123
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
124
                     (offset));
125
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_data);
126
 
127
    return config_data;
128
}
129
 
130
cyg_uint16
131
cyg_hal_sh_pcic_pci_cfg_read_word (cyg_uint32 bus, cyg_uint32 devfn,
132
                               cyg_uint32 offset)
133
{
134
    cyg_uint32 config_dword;
135
 
136
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
137
                     CYGARC_REG_PCIC_PAR_ENABLE |
138
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
139
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
140
                     (offset & ~3));
141
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
142
 
143
    return (cyg_uint16)((config_dword >> ((offset & 3) * 8)) & 0xffff);
144
}
145
 
146
cyg_uint8
147
cyg_hal_sh_pcic_pci_cfg_read_byte (cyg_uint32 bus, cyg_uint32 devfn,
148
                               cyg_uint32 offset)
149
{
150
    cyg_uint32 config_dword;
151
 
152
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
153
                     CYGARC_REG_PCIC_PAR_ENABLE |
154
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
155
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
156
                     (offset & ~3));
157
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
158
 
159
    return (cyg_uint8)((config_dword >> ((offset & 3) * 8)) & 0xff);
160
}
161
 
162
void
163
cyg_hal_sh_pcic_pci_cfg_write_dword (cyg_uint32 bus, cyg_uint32 devfn,
164
                                 cyg_uint32 offset, cyg_uint32 data)
165
{
166
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
167
                     CYGARC_REG_PCIC_PAR_ENABLE |
168
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
169
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
170
                     (offset));
171
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PDR, data);
172
}
173
 
174
void
175
cyg_hal_sh_pcic_pci_cfg_write_word (cyg_uint32 bus, cyg_uint32 devfn,
176
                                cyg_uint32 offset, cyg_uint16 data)
177
{
178
    cyg_uint32 config_dword, shift;
179
 
180
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
181
                     CYGARC_REG_PCIC_PAR_ENABLE |
182
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
183
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
184
                     (offset & ~3));
185
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
186
 
187
    shift = (offset & 3) * 8;
188
    config_dword &= ~(0xffff << shift);
189
    config_dword |= (data << shift);
190
 
191
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
192
                     CYGARC_REG_PCIC_PAR_ENABLE |
193
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
194
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
195
                     (offset & ~3));
196
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
197
}
198
 
199
void
200
cyg_hal_sh_pcic_pci_cfg_write_byte (cyg_uint32 bus, cyg_uint32 devfn,
201
                                cyg_uint32 offset, cyg_uint8  data)
202
{
203
    cyg_uint32 config_dword, shift;
204
 
205
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
206
                     CYGARC_REG_PCIC_PAR_ENABLE |
207
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
208
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
209
                     (offset & ~3));
210
    HAL_READ_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
211
 
212
    shift = (offset & 3) * 8;
213
    config_dword &= ~(0xff << shift);
214
    config_dword |= (data << shift);
215
 
216
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PAR,
217
                     CYGARC_REG_PCIC_PAR_ENABLE |
218
                     (bus << CYGARC_REG_PCIC_PAR_BUSNO_shift) |
219
                     (devfn << CYGARC_REG_PCIC_PAR_FUNC_shift) |
220
                     (offset & ~3));
221
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_PDR, config_dword);
222
}
223
 
224
//--------------------------------------------------------------------------
225
// IO space accessor functions
226
 
227
void
228
cyg_hal_sh_pcic_pci_io_write_byte (cyg_uint32 addr, cyg_uint8 data)
229
{
230
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
231
    HAL_WRITE_UINT8(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
232
                    data);
233
}
234
 
235
void
236
cyg_hal_sh_pcic_pci_io_write_word (cyg_uint32 addr, cyg_uint16 data)
237
{
238
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
239
    HAL_WRITE_UINT16(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
240
                     data);
241
}
242
 
243
void
244
cyg_hal_sh_pcic_pci_io_write_dword (cyg_uint32 addr, cyg_uint32 data)
245
{
246
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
247
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
248
                     data);
249
}
250
 
251
cyg_uint8
252
cyg_hal_sh_pcic_pci_io_read_byte (cyg_uint32 addr)
253
{
254
    cyg_uint8 data;
255
 
256
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
257
    HAL_READ_UINT8(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
258
                   data);
259
    return data;
260
}
261
 
262
cyg_uint16
263
cyg_hal_sh_pcic_pci_io_read_word (cyg_uint32 addr)
264
{
265
    cyg_uint16 data;
266
 
267
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
268
    HAL_READ_UINT16(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
269
                    data);
270
    return data;
271
}
272
 
273
cyg_uint32
274
cyg_hal_sh_pcic_pci_io_read_dword (cyg_uint32 addr)
275
{
276
    cyg_uint32 data;
277
 
278
    HAL_WRITE_UINT32(CYGARC_REG_PCIC_IOBR, addr & CYGARC_REG_PCIC_IOBR_MASK);
279
    HAL_READ_UINT32(CYGARC_REG_PCIC_IO_BASE + (addr & CYGARC_REG_PCIC_IO_BASE_MASK),
280
                    data);
281
    return data;
282
}

powered by: WebSVN 2.1.0

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