import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / include / asm-ppc64 / iSeries / iSeries_dma.h
1 /*
2  * iSeries_dma.h
3  * Copyright (C) 2001  Mike Corrigan IBM Corporation
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18  */
19
20 #ifndef _ISERIES_DMA_H
21 #define _ISERIES_DMA_H
22
23 #include <asm/types.h>
24 #ifndef __LINUX_SPINLOCK_H
25 #include <linux/spinlock.h>
26 #endif
27
28 // NUM_TCE_LEVELS defines the largest contiguous block
29 // of dma (tce) space we can get.  NUM_TCE_LEVELS = 10 
30 // allows up to 2**9 pages (512 * 4096) = 2 MB
31 #define NUM_TCE_LEVELS 10
32
33 #define NO_TCE ((dma_addr_t)-1)
34
35 // Tces come in two formats, one for the virtual bus and a different
36 // format for PCI
37 #define TCE_VB  0
38 #define TCE_PCI 1
39
40
41 union Tce {
42         u64     wholeTce;
43         struct {
44                 u64     cacheBits       :6;     /* Cache hash bits - not used */
45                 u64     rsvd            :6;     
46                 u64     rpn             :40;    /* Absolute page number */
47                 u64     valid           :1;     /* Tce is valid (vb only) */
48                 u64     allIo           :1;     /* Tce is valid for all lps (vb only) */
49                 u64     lpIndex         :8;     /* LpIndex for user of TCE (vb only) */
50                 u64     pciWrite        :1;     /* Write allowed (pci only) */
51                 u64     readWrite       :1;     /* Read allowed (pci), Write allowed
52                                                    (vb) */
53         } tceBits;
54 };
55
56 struct Bitmap {
57         unsigned long   numBits;
58         unsigned long   numBytes;
59         unsigned char * map;
60 };
61
62 struct MultiLevelBitmap {
63         unsigned long   maxLevel;
64         struct Bitmap   level[NUM_TCE_LEVELS];
65 };
66
67 struct TceTable {
68         u64     busNumber;
69         u64     size;
70         u64     startOffset;
71         u64     index;
72         spinlock_t      lock;
73         struct MultiLevelBitmap mlbm;
74 };
75
76 struct HvTceTableManagerCB {
77         u64     busNumber;              /* Bus number for this tce table */
78         u64     start;                  /* Will be NULL for secondary */
79         u64     totalSize;              /* Size (in pages) of whole table */
80         u64     startOffset;            /* Index into real tce table of the
81                                            start of our section */
82         u64     size;                   /* Size (in pages) of our section */
83         u64     index;                  /* Index of this tce table (token?) */
84         u16     maxTceTableIndex;       /* Max number of tables for partition */
85         u8      virtualBusFlag;         /* Flag to indicate virtual bus */
86         u8      rsvd[5];
87 };
88
89 extern struct TceTable virtBusTceTable; /* Tce table for virtual bus */
90
91 extern struct TceTable * build_tce_table( struct HvTceTableManagerCB *,
92                                           struct TceTable *);
93 extern void              create_virtual_bus_tce_table( void );
94
95 extern void              create_pci_bus_tce_table( unsigned busNumber );
96
97 #endif // _ISERIES_DMA_H