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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [xscale/] [verde/] [v2_0/] [src/] [verde_pci.c] - Blame information for rev 773

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      verde_pci.c
4
//
5
//      HAL support code for Verde PCI
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):    msalter
44
// Contributors: msalter
45
// Date:         2002-01-30
46
// Purpose:      PCI support
47
// Description:  Implementations of HAL PCI interfaces
48
//
49
//####DESCRIPTIONEND####
50
//
51
//========================================================================*/
52
 
53
#include <pkgconf/hal.h>
54
#include <pkgconf/system.h>
55
#include CYGBLD_HAL_PLATFORM_H
56
 
57
#include <cyg/infra/cyg_type.h>         // base types
58
#include <cyg/infra/cyg_trac.h>         // tracing macros
59
#include <cyg/infra/cyg_ass.h>          // assertion macros
60
 
61
#include <cyg/hal/hal_io.h>             // IO macros
62
#include <cyg/hal/hal_if.h>             // calling interface API
63
#include <cyg/hal/hal_arch.h>           // Register state info
64
#include <cyg/hal/hal_diag.h>
65
#include <cyg/hal/hal_intr.h>           // Interrupt names
66
#include <cyg/hal/hal_cache.h>
67
#include <cyg/io/pci_hw.h>
68
#include <cyg/io/pci.h>
69
 
70
#ifdef CYGPKG_IO_PCI
71
 
72
// Use "naked" attribute to suppress C prologue/epilogue
73
// This is a data abort handler which simply returns. Data aborts
74
// occur during configuration cycles if no device is present.
75
static void __attribute__ ((naked))
76
__pci_abort_handler(void)
77
{
78
    asm ( "subs pc, lr, #4\n" );
79
}
80
 
81
static cyg_uint32 orig_abort_vec;
82
 
83
#define DEBUG_CONFIG_VERBOSE 0
84
 
85
static inline void
86
pci_config_setup(cyg_uint32 bus, cyg_uint32 devfn, cyg_uint32 offset)
87
{
88
    cyg_uint32 dev = CYG_PCI_DEV_GET_DEV(devfn);
89
    cyg_uint32 fn  = CYG_PCI_DEV_GET_FN(devfn);
90
    cyg_uint8 localbus;
91
 
92
    localbus = (*ATU_PCIXSR >> 8) & 0xff;
93
    if (localbus == 0xff)
94
        localbus = 0;
95
 
96
    /* Offsets must be dword-aligned */
97
    offset &= ~3;
98
 
99
    /* Immediate bus use type 0 config, all others use type 1 config */
100
#if DEBUG_CONFIG_VERBOSE
101
    diag_printf("config: localbus[%d] bus[%d] dev[%d] fn[%d] offset[0x%x]\n",
102
                localbus, bus, dev, fn, offset);
103
#endif
104
 
105
    if (bus == localbus)
106
        *ATU_OCCAR = ( (1 << (dev + 16)) | (fn << 8) | offset | 0 );
107
    else
108
        *ATU_OCCAR = ( (bus << 16) | (dev << 11) | (fn << 8) | offset | 1 );
109
 
110
    orig_abort_vec = ((volatile cyg_uint32 *)0x20)[4];
111
    ((volatile unsigned *)0x20)[4] = (unsigned)__pci_abort_handler;
112
}
113
 
114
static inline int
115
pci_config_cleanup(cyg_uint32 bus)
116
{
117
    cyg_uint32 status = 0, err = 0;
118
 
119
    status = *ATU_ATUSR;
120
    if ((status & 0xF900) != 0) {
121
        err = 1;
122
        *ATU_ATUSR = status & 0xF900;
123
    }
124
 
125
    ((volatile unsigned *)0x20)[4] = orig_abort_vec;
126
 
127
    return err;
128
}
129
 
130
 
131
cyg_uint32
132
cyg_hal_plf_pci_cfg_read_dword (cyg_uint32 bus, cyg_uint32 devfn, cyg_uint32 offset)
133
{
134
    cyg_uint32 config_data;
135
    int err;
136
 
137
    pci_config_setup(bus, devfn, offset);
138
 
139
    config_data = *ATU_OCCDR;
140
 
141
    err = pci_config_cleanup(bus);
142
 
143
#if DEBUG_CONFIG_VERBOSE
144
    diag_printf("config read dword: data[0x%x] err[%d]\n",
145
                config_data, err);
146
#endif
147
    if (err)
148
      return 0xffffffff;
149
    else
150
      return config_data;
151
}
152
 
153
 
154
void
155
cyg_hal_plf_pci_cfg_write_dword (cyg_uint32 bus,
156
                                 cyg_uint32 devfn,
157
                                 cyg_uint32 offset,
158
                                 cyg_uint32 data)
159
{
160
    int err;
161
 
162
    pci_config_setup(bus, devfn, offset);
163
 
164
    *ATU_OCCDR = data;
165
 
166
    err = pci_config_cleanup(bus);
167
 
168
#if DEBUG_CONFIG_VERBOSE
169
    diag_printf("config write dword: data[0x%x] err[%d]\n",
170
                data, err);
171
#endif
172
}
173
 
174
 
175
cyg_uint16
176
cyg_hal_plf_pci_cfg_read_word (cyg_uint32 bus,
177
                               cyg_uint32 devfn,
178
                               cyg_uint32 offset)
179
{
180
    cyg_uint16 config_data;
181
    int err;
182
 
183
    pci_config_setup(bus, devfn, offset & ~3);
184
 
185
    config_data = (cyg_uint16)(((*ATU_OCCDR) >> ((offset % 0x4) * 8)) & 0xffff);
186
 
187
    err = pci_config_cleanup(bus);
188
 
189
#if DEBUG_CONFIG_VERBOSE
190
    diag_printf("config read word: data[0x%x] err[%d]\n",
191
                config_data, err);
192
#endif
193
    if (err)
194
      return 0xffff;
195
    else
196
      return config_data;
197
}
198
 
199
void
200
cyg_hal_plf_pci_cfg_write_word (cyg_uint32 bus,
201
                                cyg_uint32 devfn,
202
                                cyg_uint32 offset,
203
                                cyg_uint16 data)
204
{
205
    int err;
206
    cyg_uint32 mask, temp;
207
 
208
    pci_config_setup(bus, devfn, offset & ~3);
209
 
210
    mask = ~(0x0000ffff << ((offset % 0x4) * 8));
211
 
212
    temp = (cyg_uint32)(((cyg_uint32)data) << ((offset % 0x4) * 8));
213
    *ATU_OCCDR = (*ATU_OCCDR & mask) | temp;
214
 
215
    err = pci_config_cleanup(bus);
216
 
217
#if DEBUG_CONFIG_VERBOSE
218
    diag_printf("config write word: data[0x%x] err[%d]\n",
219
                data, err);
220
#endif
221
}
222
 
223
cyg_uint8
224
cyg_hal_plf_pci_cfg_read_byte (cyg_uint32 bus,
225
                               cyg_uint32 devfn,
226
                               cyg_uint32 offset)
227
{
228
    int err;
229
    cyg_uint8 config_data;
230
 
231
    pci_config_setup(bus, devfn, offset & ~3);
232
 
233
    config_data = (cyg_uint8)(((*ATU_OCCDR) >> ((offset % 0x4) * 8)) & 0xff);
234
 
235
    err = pci_config_cleanup(bus);
236
 
237
#if DEBUG_CONFIG_VERBOSE
238
    diag_printf("config read byte: data[0x%x] err[%d]\n",
239
                config_data, err);
240
#endif
241
    if (err)
242
        return 0xff;
243
    else
244
        return config_data;
245
}
246
 
247
 
248
void
249
cyg_hal_plf_pci_cfg_write_byte (cyg_uint32 bus,
250
                                cyg_uint32 devfn,
251
                                cyg_uint32 offset,
252
                                cyg_uint8 data)
253
{
254
    int err;
255
    cyg_uint32 mask, temp;
256
 
257
    pci_config_setup(bus, devfn, offset & ~3);
258
 
259
    mask = ~(0x000000ff << ((offset % 0x4) * 8));
260
    temp = (cyg_uint32)(((cyg_uint32)data) << ((offset % 0x4) * 8));
261
    *ATU_OCCDR = (*ATU_OCCDR & mask) | temp;
262
 
263
    err = pci_config_cleanup(bus);
264
 
265
#if DEBUG_CONFIG_VERBOSE
266
    diag_printf("config write byte: data[0x%x] err[%d]\n",
267
                data, err);
268
#endif
269
}
270
 
271
#endif // CYGPKG_IO_PCI
272
 
273
 

powered by: WebSVN 2.1.0

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