569aba5e2b35dc2be12cd8a53ae01065f5bd8460
[linux-flexiantxendom0-3.2.10.git] / include / asm-ia64 / sn / pci / pcibr_private.h
1 /* $Id$
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
8  */
9 #ifndef _ASM_SN_PCI_PCIBR_PRIVATE_H
10 #define _ASM_SN_PCI_PCIBR_PRIVATE_H
11
12 /*
13  * pcibr_private.h -- private definitions for pcibr
14  * only the pcibr driver (and its closest friends)
15  * should ever peek into this file.
16  */
17
18 #include <linux/config.h>
19 #include <asm/sn/pci/pcibr.h>
20 #include <asm/sn/pci/pciio_private.h>
21 #include <asm/sn/ksys/l1.h>
22
23 /*
24  * convenience typedefs
25  */
26
27 typedef uint64_t pcibr_DMattr_t;
28 typedef uint32_t pcibr_ATEattr_t;
29
30 typedef struct pcibr_info_s *pcibr_info_t, **pcibr_info_h;
31 typedef struct pcibr_soft_s *pcibr_soft_t;
32 typedef struct pcibr_soft_slot_s *pcibr_soft_slot_t;
33 typedef struct pcibr_hints_s *pcibr_hints_t;
34 typedef struct pcibr_intr_list_s *pcibr_intr_list_t;
35 typedef struct pcibr_intr_wrap_s *pcibr_intr_wrap_t;
36 typedef struct pcibr_intr_cbuf_s *pcibr_intr_cbuf_t;
37
38 typedef volatile unsigned *cfg_p;
39 typedef volatile bridgereg_t *reg_p;
40
41 /*
42  * extern functions
43  */
44 cfg_p pcibr_slot_config_addr(bridge_t *, pciio_slot_t, int);
45 cfg_p pcibr_func_config_addr(bridge_t *, pciio_bus_t bus, pciio_slot_t, pciio_function_t, int);
46 unsigned pcibr_slot_config_get(bridge_t *, pciio_slot_t, int);
47 unsigned pcibr_func_config_get(bridge_t *, pciio_slot_t, pciio_function_t, int);
48 void pcibr_debug(uint32_t, devfs_handle_t, char *, ...);
49 void pcibr_slot_config_set(bridge_t *, pciio_slot_t, int, unsigned);
50 void pcibr_func_config_set(bridge_t *, pciio_slot_t, pciio_function_t, int, 
51                                                                 unsigned);
52 /*
53  * PCIBR_DEBUG() macro and debug bitmask defines
54  */
55 /* low freqency debug events (ie. initialization, resource allocation,...) */
56 #define PCIBR_DEBUG_INIT        0x00000001  /* bridge init */
57 #define PCIBR_DEBUG_HINTS       0x00000002  /* bridge hints */
58 #define PCIBR_DEBUG_ATTACH      0x00000004  /* bridge attach */
59 #define PCIBR_DEBUG_DETACH      0x00000008  /* bridge detach */
60 #define PCIBR_DEBUG_ATE         0x00000010  /* bridge ATE allocation */
61 #define PCIBR_DEBUG_RRB         0x00000020  /* bridge RRB allocation */
62 #define PCIBR_DEBUG_RBAR        0x00000040  /* bridge RBAR allocation */
63 #define PCIBR_DEBUG_PROBE       0x00000080  /* bridge device probing */
64 #define PCIBR_DEBUG_INTR_ERROR  0x00000100  /* bridge error interrupt */
65 #define PCIBR_DEBUG_ERROR_HDLR  0x00000200  /* bridge error handler */
66 #define PCIBR_DEBUG_CONFIG      0x00000400  /* device's config space */
67 #define PCIBR_DEBUG_BAR         0x00000800  /* device's BAR allocations */
68 #define PCIBR_DEBUG_INTR_ALLOC  0x00001000  /* device's intr allocation */
69 #define PCIBR_DEBUG_DEV_ATTACH  0x00002000  /* device's attach */
70 #define PCIBR_DEBUG_DEV_DETACH  0x00004000  /* device's detach */
71 #define PCIBR_DEBUG_HOTPLUG     0x00008000
72
73 /* high freqency debug events (ie. map allocation, direct translation,...) */
74 #define PCIBR_DEBUG_DEVREG      0x04000000  /* bridges device reg sets */
75 #define PCIBR_DEBUG_PIOMAP      0x08000000  /* pcibr_piomap */
76 #define PCIBR_DEBUG_PIODIR      0x10000000  /* pcibr_piotrans */
77 #define PCIBR_DEBUG_DMAMAP      0x20000000  /* pcibr_dmamap */
78 #define PCIBR_DEBUG_DMADIR      0x40000000  /* pcibr_dmatrans */
79 #define PCIBR_DEBUG_INTR        0x80000000  /* interrupts */
80
81 extern char      *pcibr_debug_module;
82 extern int        pcibr_debug_widget;
83 extern int        pcibr_debug_slot;
84 extern uint32_t pcibr_debug_mask;
85
86 /* For low frequency events (ie. initialization, resource allocation,...) */
87 #define PCIBR_DEBUG_ALWAYS(args) pcibr_debug args ;
88
89 /* XXX: habeck: maybe make PCIBR_DEBUG() always available?  Even in non-
90  * debug kernels?  If tracing isn't enabled (i.e pcibr_debug_mask isn't
91  * set, then the overhead for this macro is just an extra 'if' check.
92  */
93 /* For high frequency events (ie. map allocation, direct translation,...) */
94 #if 1 || DEBUG
95 #define PCIBR_DEBUG(args) PCIBR_DEBUG_ALWAYS(args)
96 #else   /* DEBUG */
97 #define PCIBR_DEBUG(args)
98 #endif  /* DEBUG */
99
100 /*
101  * Bridge sets up PIO using this information.
102  */
103 struct pcibr_piomap_s {
104     struct pciio_piomap_s   bp_pp;      /* generic stuff */
105
106 #define bp_flags        bp_pp.pp_flags  /* PCIBR_PIOMAP flags */
107 #define bp_dev          bp_pp.pp_dev    /* associated pci card */
108 #define bp_slot         bp_pp.pp_slot   /* which slot the card is in */
109 #define bp_space        bp_pp.pp_space  /* which address space */
110 #define bp_pciaddr      bp_pp.pp_pciaddr        /* starting offset of mapping */
111 #define bp_mapsz        bp_pp.pp_mapsz  /* size of this mapping */
112 #define bp_kvaddr       bp_pp.pp_kvaddr /* kernel virtual address to use */
113
114     iopaddr_t               bp_xtalk_addr;      /* corresponding xtalk address */
115     xtalk_piomap_t          bp_xtalk_pio;       /* corresponding xtalk resource */
116     pcibr_piomap_t          bp_next;    /* Next piomap on the list */
117     pcibr_soft_t            bp_soft;    /* backpointer to bridge soft data */
118     atomic_t                bp_toc[1];  /* PCI timeout counter */
119
120 };
121
122 /*
123  * Bridge sets up DMA using this information.
124  */
125 struct pcibr_dmamap_s {
126     struct pciio_dmamap_s   bd_pd;
127 #define bd_flags        bd_pd.pd_flags  /* PCIBR_DMAMAP flags */
128 #define bd_dev          bd_pd.pd_dev    /* associated pci card */
129 #define bd_slot         bd_pd.pd_slot   /* which slot the card is in */
130     struct pcibr_soft_s    *bd_soft;    /* pcibr soft state backptr */
131     xtalk_dmamap_t          bd_xtalk;   /* associated xtalk resources */
132
133     size_t                  bd_max_size;        /* maximum size of mapping */
134     xwidgetnum_t            bd_xio_port;        /* target XIO port */
135     iopaddr_t               bd_xio_addr;        /* target XIO address */
136     iopaddr_t               bd_pci_addr;        /* via PCI address */
137
138     int                     bd_ate_index;       /* Address Translation Entry Index */
139     int                     bd_ate_count;       /* number of ATE's allocated */
140     bridge_ate_p            bd_ate_ptr;         /* where to write first ATE */
141     bridge_ate_t            bd_ate_proto;       /* prototype ATE (for xioaddr=0) */
142     bridge_ate_t            bd_ate_prime;       /* value of 1st ATE written */
143 };
144
145 #define IBUFSIZE        5               /* size of circular buffer (holds 4) */
146
147 /*
148  * Circular buffer used for interrupt processing
149  */
150 struct pcibr_intr_cbuf_s {
151     spinlock_t          ib_lock;                /* cbuf 'put' lock */
152     int                 ib_in;                  /* index of next free entry */
153     int                 ib_out;                 /* index of next full entry */
154     pcibr_intr_wrap_t   ib_cbuf[IBUFSIZE];      /* circular buffer of wrap  */
155 };
156
157 /*
158  * Bridge sets up interrupts using this information.
159  */
160
161 struct pcibr_intr_s {
162     struct pciio_intr_s     bi_pi;
163 #define bi_flags        bi_pi.pi_flags  /* PCIBR_INTR flags */
164 #define bi_dev          bi_pi.pi_dev    /* associated pci card */
165 #define bi_lines        bi_pi.pi_lines  /* which PCI interrupt line(s) */
166 #define bi_func         bi_pi.pi_func   /* handler function (when connected) */
167 #define bi_arg          bi_pi.pi_arg    /* handler parameter (when connected) */
168 #define bi_mustruncpu   bi_pi.pi_mustruncpu /* Where we must run. */
169 #define bi_irq          bi_pi.pi_irq    /* IRQ assigned. */
170 #define bi_cpu          bi_pi.pi_cpu    /* cpu assigned. */
171     unsigned                bi_ibits;   /* which Bridge interrupt bit(s) */
172     pcibr_soft_t            bi_soft;    /* shortcut to soft info */
173     struct pcibr_intr_cbuf_s bi_ibuf;   /* circular buffer of wrap ptrs */
174 };
175
176
177 /* 
178  * PCIBR_INFO_SLOT_GET_EXT returns the external slot number that the card
179  * resides in.  (i.e the slot number silk screened on the back of the I/O 
180  * brick).  PCIBR_INFO_SLOT_GET_INT returns the internal slot (or device)
181  * number used by the pcibr code to represent that external slot (i.e to 
182  * set bit patterns in BRIDGE/PIC registers to represent the device, or to
183  * offset into an array, or ...).
184  *
185  * In BRIDGE and XBRIDGE the external slot and internal device numbering 
186  * are the same.  (0->0, 1->1, 2->2,... 7->7)  BUT in the PIC the external
187  * slot number is always 1 greater than the internal device number (1->0, 
188  * 2->1, 3->2, 4->3).  This is due to the fact that the PCI-X spec requires
189  * that the 'bridge' (i.e PIC) be designated as 'device 0', thus external
190  * slot numbering can't start at zero.
191  *
192  * PCIBR_DEVICE_TO_SLOT converts an internal device number to an external
193  * slot number.  NOTE: PCIIO_SLOT_NONE stays as PCIIO_SLOT_NONE.
194  *
195  * PCIBR_SLOT_TO_DEVICE converts an external slot number to an internal
196  * device number.  NOTE: PCIIO_SLOT_NONE stays as PCIIO_SLOT_NONE.
197  */
198 #define PCIBR_INFO_SLOT_GET_EXT(info)       (((pcibr_info_t)info)->f_slot)
199 #define PCIBR_INFO_SLOT_GET_INT(info)       (((pcibr_info_t)info)->f_dev)
200
201 #define PCIBR_DEVICE_TO_SLOT(pcibr_soft, dev_num) \
202         (((dev_num) != PCIIO_SLOT_NONE) ? \
203             (IS_PIC_SOFT((pcibr_soft)) ? ((dev_num) + 1) : (dev_num)) : \
204             PCIIO_SLOT_NONE)
205
206 #define PCIBR_SLOT_TO_DEVICE(pcibr_soft, slot) \
207         (((slot) != PCIIO_SLOT_NONE) ? \
208             (IS_PIC_SOFT((pcibr_soft)) ? ((slot) - 1) : (slot)) : \
209             PCIIO_SLOT_NONE)
210
211 /*
212  * per-connect point pcibr data, including standard pciio data in-line:
213  */
214 struct pcibr_info_s {
215     struct pciio_info_s     f_c;        /* MUST BE FIRST. */
216 #define f_vertex        f_c.c_vertex    /* back pointer to vertex */
217 #define f_bus           f_c.c_bus       /* which bus the card is in */
218 #define f_slot          f_c.c_slot      /* which slot the card is in */
219 #define f_func          f_c.c_func      /* which func (on multi-func cards) */
220 #define f_vendor        f_c.c_vendor    /* PCI card "vendor" code */
221 #define f_device        f_c.c_device    /* PCI card "device" code */
222 #define f_master        f_c.c_master    /* PCI bus provider */
223 #define f_mfast         f_c.c_mfast     /* cached fastinfo from c_master */
224 #define f_pops          f_c.c_pops      /* cached provider from c_master */
225 #define f_efunc         f_c.c_efunc     /* error handling function */
226 #define f_einfo         f_c.c_einfo     /* first parameter for efunc */
227 #define f_window        f_c.c_window    /* state of BASE regs */
228 #define f_rwindow       f_c.c_rwindow   /* expansion ROM BASE regs */
229 #define f_rbase         f_c.c_rbase     /* expansion ROM base */
230 #define f_rsize         f_c.c_rsize     /* expansion ROM size */
231 #define f_piospace      f_c.c_piospace  /* additional I/O spaces allocated */
232
233     /* pcibr-specific connection state */
234     int                     f_ibit[4];  /* Bridge bit for each INTx */
235     pcibr_piomap_t          f_piomap;
236     int                     f_att_det_error;
237     pciio_slot_t            f_dev;      /* which device the card represents */
238     cap_pcix_type0_t       *f_pcix_cap; /* pointer to the pcix capability */
239 };
240
241 /* =====================================================================
242  *          Shared Interrupt Information
243  */
244
245 struct pcibr_intr_list_s {
246     pcibr_intr_list_t       il_next;
247     pcibr_intr_t            il_intr;
248     volatile bridgereg_t   *il_wrbf;    /* ptr to b_wr_req_buf[] */
249 };
250
251 /* =====================================================================
252  *          Interrupt Wrapper Data
253  */
254 struct pcibr_intr_wrap_s {
255     pcibr_soft_t            iw_soft;    /* which bridge */
256     volatile bridgereg_t   *iw_stat;    /* ptr to b_int_status */
257 #ifdef CONFIG_IA64_SGI_SN1
258     bridgereg_t             iw_intr;    /* bit in b_int_status */
259 #else
260     bridgereg_t             iw_ibit;    /* bit in b_int_status */
261 #endif
262     pcibr_intr_list_t       iw_list;    /* ghostbusters! */
263     int                     iw_hdlrcnt; /* running handler count */
264     int                     iw_shared;  /* if Bridge bit is shared */
265     int                     iw_connected; /* if already connected */
266 };
267
268 #define PCIBR_ISR_ERR_START             8
269 #define PCIBR_ISR_MAX_ERRS_BRIDGE       32
270 #define PCIBR_ISR_MAX_ERRS_PIC          45
271 #define PCIBR_ISR_MAX_ERRS      PCIBR_ISR_MAX_ERRS_PIC
272
273 /*
274  * PCI Base Address Register window allocation constants.
275  * To reduce the size of the internal resource mapping structures, do
276  * not use the entire PCI bus I/O address space
277  */ 
278 #define PCIBR_BUS_IO_BASE      0x100000
279 #define PCIBR_BUS_IO_MAX       0x0FFFFFFF
280 #define PCIBR_BUS_IO_PAGE      0x100000
281
282 #define PCIBR_BUS_SWIN_BASE    _PAGESZ
283 #define PCIBR_BUS_SWIN_MAX     0x000FFFFF
284 #define PCIBR_BUS_SWIN_PAGE    _PAGESZ
285
286 #define PCIBR_BUS_MEM_BASE     0x200000
287 #define PCIBR_BUS_MEM_MAX      0x3FFFFFFF
288 #define PCIBR_BUS_MEM_PAGE     0x100000
289
290 /* defines for pcibr_soft_s->bs_bridge_type */
291 #define PCIBR_BRIDGETYPE_BRIDGE         0
292 #define PCIBR_BRIDGETYPE_XBRIDGE        1
293 #define PCIBR_BRIDGETYPE_PIC            2
294 #define IS_XBRIDGE_SOFT(ps) (ps->bs_bridge_type == PCIBR_BRIDGETYPE_XBRIDGE)
295 #define IS_PIC_SOFT(ps)     (ps->bs_bridge_type == PCIBR_BRIDGETYPE_PIC)
296 #define IS_BRIDGE_SOFT(ps)  (ps->bs_bridge_type == PCIBR_BRIDGETYPE_BRIDGE)
297 #define IS_XBRIDGE_OR_PIC_SOFT(ps) (IS_XBRIDGE_SOFT(ps) || IS_PIC_SOFT(ps))
298
299 /*
300  * Runtime checks for workarounds.
301  */
302 #define PCIBR_WAR_ENABLED(pv, pcibr_soft) \
303         ((1 << XWIDGET_PART_REV_NUM_REV(pcibr_soft->bs_rev_num)) & pv)
304 /*
305  * Defines for individual WARs. Each is a bitmask of applicable
306  * part revision numbers. (1 << 1) == rev A, (1 << 2) == rev B, etc.
307  */
308 #define PV854697 (~0)     /* PIC: write 64bit regs as 64bits. permanent */
309 #define PV854827 (~0)     /* PIC: fake widget 0xf presence bit. permanent */
310 #define PV855271 (~0)     /* PIC: use virt chan iff 64-bit device. permanent */
311 #define PV855272 (1 << 1) /* PIC: runaway interrupt WAR */
312 #define PV856155 (1 << 1) /* PIC: arbitration WAR */
313 #define PV856864 (1 << 1) /* PIC: lower timeout to free TNUMs quicker */
314 #define PV856866 (1 << 1) /* PIC: avoid rrb's 0/1/8/9. */
315 #define PV862253 (1 << 1) /* PIC: don't enable write req RAM parity checking */
316 #define PV867308 (3 << 1) /* PIC: make LLP error interrupts FATAL for PIC */
317
318
319 /* defines for pcibr_soft_s->bs_bridge_mode */
320 #define PCIBR_BRIDGEMODE_PCI_33         0x0
321 #define PCIBR_BRIDGEMODE_PCI_66         0x2
322 #define PCIBR_BRIDGEMODE_PCIX_66        0x3
323 #define PCIBR_BRIDGEMODE_PCIX_100       0x5
324 #define PCIBR_BRIDGEMODE_PCIX_133       0x7
325 #define BUSSPEED_MASK                   0x6
326 #define BUSTYPE_MASK                    0x1
327
328 #define IS_PCI(ps)      (!IS_PCIX(ps))
329 #define IS_PCIX(ps)     ((ps)->bs_bridge_mode & BUSTYPE_MASK)
330
331 #define IS_33MHZ(ps)    ((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCI_33)
332 #define IS_66MHZ(ps)    (((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCI_66) || \
333                          ((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCIX_66))
334 #define IS_100MHZ(ps)   ((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCIX_100)
335 #define IS_133MHZ(ps)   ((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCIX_133)
336
337
338 /* Number of PCI slots.   NOTE: this works as long as the first slot
339  * is zero.  Otherwise use ((ps->bs_max_slot+1) - ps->bs_min_slot)
340  */
341 #define PCIBR_NUM_SLOTS(ps) (ps->bs_max_slot+1)
342
343 /* =====================================================================
344  *            Bridge Device State structure
345  *
346  *      one instance of this structure is kept for each
347  *      Bridge ASIC in the system.
348  */
349
350 struct pcibr_soft_s {
351     devfs_handle_t          bs_conn;            /* xtalk connection point */
352     devfs_handle_t          bs_vhdl;            /* vertex owned by pcibr */
353     uint64_t                bs_int_enable;      /* Mask of enabled intrs */
354     bridge_t               *bs_base;            /* PIO pointer to Bridge chip */
355     char                   *bs_name;            /* hw graph name */
356     xwidgetnum_t            bs_xid;             /* Bridge's xtalk ID number */
357     devfs_handle_t          bs_master;          /* xtalk master vertex */
358     xwidgetnum_t            bs_mxid;            /* master's xtalk ID number */
359     pciio_slot_t            bs_first_slot;      /* first existing slot */
360     pciio_slot_t            bs_last_slot;       /* last existing slot */
361     pciio_slot_t            bs_last_reset;      /* last slot to reset */
362     pciio_slot_t            bs_min_slot;        /* lowest possible slot */
363     pciio_slot_t            bs_max_slot;        /* highest possible slot */
364     pcibr_soft_t            bs_peers_soft;      /* PICs other bus's soft */
365     int                     bs_busnum;          /* PIC has two pci busses */
366
367     iopaddr_t               bs_dir_xbase;       /* xtalk address for 32-bit PCI direct map */
368     xwidgetnum_t            bs_dir_xport;       /* xtalk port for 32-bit PCI direct map */
369
370     struct map             *bs_int_ate_map;     /* rmalloc map for internal ATEs */
371     struct map             *bs_ext_ate_map;     /* rmalloc map for external ATEs */
372     short                   bs_int_ate_size;    /* number of internal ates */
373     short                   bs_bridge_type;     /* see defines above */
374     short                   bs_bridge_mode;     /* see defines above */
375 #ifdef CONFIG_IA64_SGI_SN1
376 #define bs_xbridge          bs_bridge_type
377 #endif
378     int                     bs_rev_num;         /* revision number of Bridge */
379
380     /* bs_dma_flags are the forced dma flags used on all DMAs. Used for
381      * working around ASIC rev issues and protocol specific requirements
382      */
383     unsigned                bs_dma_flags;       /* forced DMA flags */
384
385 #ifdef CONFIG_IA64_SGI_SN1
386     l1sc_t                 *bs_l1sc;            /* io brick l1 system cntr */
387 #endif
388     moduleid_t              bs_moduleid;        /* io brick moduleid */
389     short                   bs_bricktype;       /* io brick type */
390
391     /*
392      * Lock used primarily to get mutual exclusion while managing any
393      * bridge resources..
394      */
395     spinlock_t              bs_lock;
396     
397     devfs_handle_t          bs_noslot_conn;     /* NO-SLOT connection point */
398     pcibr_info_t            bs_noslot_info;
399     struct pcibr_soft_slot_s {
400         /* information we keep about each CFG slot */
401
402         /* some devices (ioc3 in non-slotted
403          * configurations, sometimes) make use
404          * of more than one REQ/GNT/INT* signal
405          * sets. The slot corresponding to the
406          * IDSEL that the device responds to is
407          * called the host slot; the slot
408          * numbers that the device is stealing
409          * REQ/GNT/INT bits from are known as
410          * the guest slots.
411          */
412         int                     has_host;
413         pciio_slot_t            host_slot;
414         devfs_handle_t          slot_conn;
415
416         /* PCI Hot-Plug status word */
417         int                     slot_status;
418
419         /* Potentially several connection points
420          * for this slot. bss_ninfo is how many,
421          * and bss_infos is a pointer to
422          * an array pcibr_info_t values (which are
423          * pointers to pcibr_info structs, stored
424          * as device_info in connection ponts).
425          */
426         int                     bss_ninfo;
427         pcibr_info_h            bss_infos;
428
429         /* Temporary Compatibility Macros, for
430          * stuff that has moved out of bs_slot
431          * and into the info structure. These
432          * will go away when their users have
433          * converted over to multifunction-
434          * friendly use of bss_{ninfo,infos}.
435          */
436 #define bss_vendor_id   bss_infos[0]->f_vendor
437 #define bss_device_id   bss_infos[0]->f_device
438 #define bss_window      bss_infos[0]->f_window
439 #define bssw_space      w_space
440 #define bssw_base       w_base
441 #define bssw_size       w_size
442
443         /* Where is DevIO(x) pointing? */
444         /* bssd_space is NONE if it is not assigned. */
445         struct {
446             pciio_space_t           bssd_space;
447             iopaddr_t               bssd_base;
448             int                     bssd_ref_cnt;
449         } bss_devio;
450
451         /* Shadow value for Device(x) register,
452          * so we don't have to go to the chip.
453          */
454         bridgereg_t             bss_device;
455
456         /* Number of sets on GBR/REALTIME bit outstanding
457          * Used by Priority I/O for tracking reservations
458          */
459         int                     bss_pri_uctr;
460
461         /* Number of "uses" of PMU, 32-bit direct,
462          * and 64-bit direct DMA (0:none, <0: trans,
463          * >0: how many dmamaps). Device(x) bits
464          * controlling attribute of each kind of
465          * channel can't be changed by dmamap_alloc
466          * or dmatrans if the controlling counter
467          * is nonzero. dmatrans is forever.
468          */
469         int                     bss_pmu_uctr;
470         int                     bss_d32_uctr;
471         int                     bss_d64_uctr;
472
473         /* When the contents of mapping configuration
474          * information is locked down by dmatrans,
475          * repeated checks of the same flags should
476          * be shortcircuited for efficiency.
477          */
478         iopaddr_t               bss_d64_base;
479         unsigned                bss_d64_flags;
480         iopaddr_t               bss_d32_base;
481         unsigned                bss_d32_flags;
482
483         /* Shadow information used for implementing
484          * Bridge Hardware WAR #484930
485          */
486         atomic_t                bss_ext_ates_active;
487         volatile unsigned      *bss_cmd_pointer;
488         unsigned                bss_cmd_shadow;
489
490     } bs_slot[8];
491
492     pcibr_intr_bits_f          *bs_intr_bits;
493
494     /* PIC PCI-X Read Buffer Management :
495      * bs_pcix_num_funcs: the total number of PCI-X functions
496      *  on the bus
497      * bs_pcix_split_tot: total number of outstanding split
498      *  transactions requested by all functions on the bus
499      * bs_pcix_rbar_percent_allowed: the percentage of the
500      *  total number of buffers a function requested that are 
501      *  available to it, not including the 1 RBAR guaranteed 
502      *  to it.
503      * bs_pcix_rbar_inuse: number of RBARs in use.
504      * bs_pcix_rbar_avail: number of RBARs available.  NOTE:
505      *  this value can go negative if we oversubscribe the 
506      *  RBARs.  (i.e.  We have 16 RBARs but 17 functions).
507      */
508     int                     bs_pcix_num_funcs;
509     int                     bs_pcix_split_tot;
510     int                     bs_pcix_rbar_percent_allowed;
511
512     int                     bs_pcix_rbar_inuse;
513     int                     bs_pcix_rbar_avail;
514
515
516     /* RRB MANAGEMENT
517      * bs_rrb_fixed: bitmap of slots whose RRB
518      *  allocations we should not "automatically" change
519      * bs_rrb_avail: number of RRBs that have not
520      *  been allocated or reserved for {even,odd} slots
521      * bs_rrb_res: number of RRBs currently reserved for the
522      *  use of the index slot number
523      * bs_rrb_res_dflt: number of RRBs reserved at boot
524      *  time for the use of the index slot number
525      * bs_rrb_valid: number of RRBs currently marked valid
526      *  for the indexed slot/vchan number; array[slot][vchan]
527      * bs_rrb_valid_dflt: number of RRBs marked valid at boot
528      *  time for the indexed slot/vchan number; array[slot][vchan]
529      */
530     int                     bs_rrb_fixed;
531     int                     bs_rrb_avail[2];
532     int                     bs_rrb_res[8];
533     int                     bs_rrb_res_dflt[8];
534 #ifdef CONFIG_IA64_SGI_SN1
535     int                     bs_rrb_valid[16];
536     int                     bs_rrb_valid_dflt[16];
537 #else
538     int                     bs_rrb_valid[8][4];
539     int                     bs_rrb_valid_dflt[8][4];
540 #endif
541     struct {
542         /* Each Bridge interrupt bit has a single XIO
543          * interrupt channel allocated.
544          */
545         xtalk_intr_t            bsi_xtalk_intr;
546         /*
547          * A wrapper structure is associated with each
548          * Bridge interrupt bit.
549          */
550         struct pcibr_intr_wrap_s  bsi_pcibr_intr_wrap;
551
552     } bs_intr[8];
553
554     xtalk_intr_t                bsi_err_intr;
555
556     /*
557      * We stash away some information in this structure on getting
558      * an error interrupt. This information is used during PIO read/
559      * write error handling.
560      *
561      * As it stands now, we do not re-enable the error interrupt
562      * till the error is resolved. Error resolution happens either at
563      * bus error time for PIO Read errors (~100 microseconds), or at
564      * the scheduled timeout time for PIO write errors (~milliseconds).
565      * If this delay causes problems, we may need to move towards
566      * a different scheme..
567      *
568      * Note that there is no locking while looking at this data structure.
569      * There should not be any race between bus error code and
570      * error interrupt code.. will look into this if needed.
571      *
572      * NOTE: The above discussion of error interrupt processing is
573      *       no longer true. Whether it should again be true, is
574      *       being looked into.
575      */
576     struct br_errintr_info {
577         int                     bserr_toutcnt;
578 #ifdef LATER
579         toid_t                  bserr_toutid;   /* Timeout started by errintr */
580 #endif  /* LATER */
581         iopaddr_t               bserr_addr;     /* Address where error occurred */
582         uint64_t                bserr_intstat;  /* interrupts active at error dump */
583     } bs_errinfo;
584
585     /*
586      * PCI Bus Space allocation data structure.
587      *
588      * The resource mapping functions rmalloc() and rmfree() are used
589      * to manage the PCI bus I/O, small window, and memory  address 
590      * spaces.
591      *
592      * This info is used to assign PCI bus space addresses to cards
593      * via their BARs and to the callers of the pcibr_piospace_alloc()
594      * interface.
595      *
596      * Users of the pcibr_piospace_alloc() interface, such as the VME
597      * Universe chip, need PCI bus space that is not acquired by BARs.
598      * Most of these users need "large" amounts of PIO space (typically
599      * in Megabytes), and they generally tend to take once and never
600      * release. 
601      */
602 #ifdef CONFIG_IA64_SGI_SN1
603     struct br_pcisp_info {
604         iopaddr_t               pci_io_base;
605         iopaddr_t               pci_io_last;
606         iopaddr_t               pci_swin_base;
607         iopaddr_t               pci_swin_last;
608         iopaddr_t               pci_mem_base;
609         iopaddr_t               pci_mem_last;
610     } bs_spinfo;
611 #endif  /* CONFIG_IA64_SGI_SN1 */
612     struct pciio_win_map_s      bs_io_win_map;  /* I/O addr space */
613     struct pciio_win_map_s      bs_swin_map;    /* Small window addr space */
614     struct pciio_win_map_s      bs_mem_win_map; /* Memory addr space */
615
616     int                   bs_bus_addr_status;    /* Bus space status */
617
618 #define PCIBR_BUS_ADDR_MEM_FREED       1  /* Reserved PROM mem addr freed */
619 #define PCIBR_BUS_ADDR_IO_FREED        2  /* Reserved PROM I/O addr freed */
620
621     struct bs_errintr_stat_s {
622         uint32_t              bs_errcount_total;
623         uint32_t              bs_lasterr_timestamp;
624         uint32_t              bs_lasterr_snapshot;
625     } bs_errintr_stat[PCIBR_ISR_MAX_ERRS];
626
627     /*
628      * Bridge-wide endianness control for
629      * large-window PIO mappings
630      *
631      * These fields are set to PCIIO_BYTE_SWAP
632      * or PCIIO_WORD_VALUES once the swapper
633      * has been configured, one way or the other,
634      * for the direct windows. If they are zero,
635      * nobody has a PIO mapping through that window,
636      * and the swapper can be set either way.
637      */
638     unsigned            bs_pio_end_io;
639     unsigned            bs_pio_end_mem;
640 };
641
642 #define PCIBR_ERRTIME_THRESHOLD         (100)
643 #define PCIBR_ERRRATE_THRESHOLD         (100)
644
645 /*
646  * pcibr will respond to hints dropped in its vertex
647  * using the following structure.
648  */
649 struct pcibr_hints_s {
650     /* ph_host_slot is actually +1 so "0" means "no host" */
651     pciio_slot_t            ph_host_slot[8];    /* REQ/GNT/INT in use by ... */
652     unsigned                ph_rrb_fixed;       /* do not change RRB allocations */
653     unsigned                ph_hands_off;       /* prevent further pcibr operations */
654     rrb_alloc_funct_t       rrb_alloc_funct;    /* do dynamic rrb allocation */
655     pcibr_intr_bits_f      *ph_intr_bits;       /* map PCI INT[ABCD] to Bridge Int(n) */
656 };
657
658 extern int              pcibr_prefetch_enable_rev, pcibr_wg_enable_rev;
659
660 /*
661  * Number of bridge non-fatal error interrupts we can see before
662  * we decide to disable that interrupt.
663  */
664 #define PCIBR_ERRINTR_DISABLE_LEVEL     10000
665
666 /* =====================================================================
667  *    Bridge (pcibr) state management functions
668  *
669  *      pcibr_soft_get is here because we do it in a lot
670  *      of places and I want to make sure they all stay
671  *      in step with each other.
672  *
673  *      pcibr_soft_set is here because I want it to be
674  *      closely associated with pcibr_soft_get, even
675  *      though it is only called in one place.
676  */
677
678 #define pcibr_soft_get(v)       ((pcibr_soft_t)hwgraph_fastinfo_get((v)))
679 #define pcibr_soft_set(v,i)     (hwgraph_fastinfo_set((v), (arbitrary_info_t)(i)))
680
681 /*
682  * mem alloc/free macros
683  */
684 #define NEWAf(ptr,n,f)  (ptr = snia_kmem_zalloc((n)*sizeof (*(ptr)), (f&PCIIO_NOSLEEP)?KM_NOSLEEP:KM_SLEEP))
685 #define NEWA(ptr,n)     (ptr = snia_kmem_zalloc((n)*sizeof (*(ptr)), KM_SLEEP))
686 #define DELA(ptr,n)     (kfree(ptr))
687
688 #define NEWf(ptr,f)     NEWAf(ptr,1,f)
689 #define NEW(ptr)        NEWA(ptr,1)
690 #define DEL(ptr)        DELA(ptr,1)
691
692 #ifndef CONFIG_IA64_SGI_SN1
693 /*
694  * Additional PIO spaces per slot are
695  * recorded in this structure.
696  */
697 struct pciio_piospace_s {
698     pciio_piospace_t        next;       /* another space for this device */
699     char                    free;       /* 1 if free, 0 if in use */
700     pciio_space_t           space;      /* Which space is in use */
701     iopaddr_t               start;      /* Starting address of the PIO space */
702     size_t                  count;      /* size of PIO space */
703 };
704 #endif  /* CONFIG_IA64_SGI_SN1 */
705
706 /* Use io spin locks. This ensures that all the PIO writes from a particular
707  * CPU to a particular IO device are synched before the start of the next
708  * set of PIO operations to the same device.
709  */
710 #ifdef PCI_LATER
711 #define pcibr_lock(pcibr_soft)          io_splock(pcibr_soft->bs_lock)
712 #define pcibr_unlock(pcibr_soft, s)     io_spunlock(pcibr_soft->bs_lock,s)
713 #else
714 #define pcibr_lock(pcibr_soft)          1
715 #define pcibr_unlock(pcibr_soft, s)     
716 #endif  /* PCI_LATER */
717
718 #ifndef CONFIG_IA64_SGI_SN1
719 #define PCIBR_VALID_SLOT(ps, s)     (s < PCIBR_NUM_SLOTS(ps))
720 #define PCIBR_D64_BASE_UNSET    (0xFFFFFFFFFFFFFFFF)
721 #define PCIBR_D32_BASE_UNSET    (0xFFFFFFFF)
722 #endif
723 #define INFO_LBL_PCIBR_ASIC_REV "_pcibr_asic_rev"
724
725 #define PCIBR_SOFT_LIST 1
726 #if PCIBR_SOFT_LIST
727 typedef struct pcibr_list_s *pcibr_list_p;
728 struct pcibr_list_s {
729         pcibr_list_p            bl_next;
730         pcibr_soft_t            bl_soft;
731         devfs_handle_t          bl_vhdl;
732 };
733 #endif /* PCIBR_SOFT_LIST */
734
735 #endif                          /* _ASM_SN_PCI_PCIBR_PRIVATE_H */