Home | History | Annotate | Line # | Download | only in sun3x
iommu.h revision 1.1
      1  1.1  gwr /*	$NetBSD: iommu.h,v 1.1 1997/01/14 20:57:09 gwr Exp $	*/
      2  1.1  gwr 
      3  1.1  gwr /*-
      4  1.1  gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  1.1  gwr  * All rights reserved.
      6  1.1  gwr  *
      7  1.1  gwr  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  gwr  * by Jeremy Cooper.
      9  1.1  gwr  *
     10  1.1  gwr  * Redistribution and use in source and binary forms, with or without
     11  1.1  gwr  * modification, are permitted provided that the following conditions
     12  1.1  gwr  * are met:
     13  1.1  gwr  * 1. Redistributions of source code must retain the above copyright
     14  1.1  gwr  *    notice, this list of conditions and the following disclaimer.
     15  1.1  gwr  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  gwr  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  gwr  *    documentation and/or other materials provided with the distribution.
     18  1.1  gwr  * 3. All advertising materials mentioning features or use of this software
     19  1.1  gwr  *    must display the following acknowledgement:
     20  1.1  gwr  *        This product includes software developed by the NetBSD
     21  1.1  gwr  *        Foundation, Inc. and its contributors.
     22  1.1  gwr  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  gwr  *    contributors may be used to endorse or promote products derived
     24  1.1  gwr  *    from this software without specific prior written permission.
     25  1.1  gwr  *
     26  1.1  gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  gwr  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  gwr  */
     38  1.1  gwr 
     39  1.1  gwr /*
     40  1.1  gwr  * Structure and definition of descriptors used in the I/O Mapper.
     41  1.1  gwr  */
     42  1.1  gwr #ifndef _SUN3X_IOMMU_H
     43  1.1  gwr #define _SUN3X_IOMMU_H
     44  1.1  gwr 
     45  1.1  gwr /* The I/O Mapper is a special type of MMU in the sun3x architecture
     46  1.1  gwr  * (and supposedly in the sun4m as well) that translates an addresses
     47  1.1  gwr  * access by a DMA device during a DMA access, into a physical destination
     48  1.1  gwr  * address; it is an MMU that stands between DMA devices and physical memory.
     49  1.1  gwr  *
     50  1.1  gwr  * The input address space managed by the I/O mapper is 24 bits wide and broken
     51  1.1  gwr  * into pages of 8K-byte size.  The output address space is a full 32 bits
     52  1.1  gwr  * wide.  The mapping of each input page is described by a page entry
     53  1.1  gwr  * descriptor.  There are exactly 2048 such descriptors in the I/O mapper, the
     54  1.1  gwr  * first entry of which is located at physical address 0x60000000 in sun3x
     55  1.1  gwr  * machines.
     56  1.1  gwr  *
     57  1.1  gwr  * Since not every device transfers to a full 24 bit address space, each
     58  1.1  gwr  * device is wired so that its address space is always flush against the
     59  1.1  gwr  * high end of the I/O mapper.  That is, a device with a 16 bit address space
     60  1.1  gwr  * can only access 64k of memory.  This 64k is wired to the top 64k in the
     61  1.1  gwr  * I/O mapper's input address space.
     62  1.1  gwr  *
     63  1.1  gwr  * In addition to describing address mappings, a page entry also indicates
     64  1.1  gwr  * whether the page is read-only, inhibits system caches from caching data
     65  1.1  gwr  * addresses to or from it, and whether or not DMA transfers must be completed
     66  1.1  gwr  * in 16 byte blocks.  (This is used for cache optimization in sun3x systems
     67  1.1  gwr  * with special DMA caches.)
     68  1.1  gwr  */
     69  1.1  gwr 
     70  1.1  gwr /** I/O MAPPER Page Entry Descriptor
     71  1.1  gwr  *  31                                                             16
     72  1.1  gwr  *  +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
     73  1.1  gwr  *  |              PAGE PHYSICAL ADDRESS BITS (31..13)              |
     74  1.1  gwr  *  +---.---.---+---.---.---.---.---.---+---+---+---+---+---+---.---+
     75  1.1  gwr  *  |           |          UNUSED       | CI| BX| M | U | WP|   DT  |
     76  1.1  gwr  *  +---.---.---+---.---.---.---.---.---+---+---+---+---+---+---.---+
     77  1.1  gwr  *  15                                                              0
     78  1.1  gwr  *
     79  1.1  gwr  * <CI> CACHE INHIBIT   - When set, prevents instructions and data from the
     80  1.1  gwr  *                        page from being cached in any system cache.
     81  1.1  gwr  * <BX> FULL BLOCK XFER - When set, requires that all devices must transfer
     82  1.1  gwr  *                        data in multiples of 16 bytes in size.
     83  1.1  gwr  * <M>  MODIFIED        - Set when the cpu has modified (written to) the
     84  1.1  gwr  *                        physical page.
     85  1.1  gwr  * <U>  USED            - Set when the cpu has accessed the physical page.
     86  1.1  gwr  * <WP> WRITE PROTECT   - When set, prevents all DMA devices from writing to the
     87  1.1  gwr  *                        page.
     88  1.1  gwr  * <DT> DESCRIPTOR TYPE - One of the following values:
     89  1.1  gwr  *                        00 = Invalid page
     90  1.1  gwr  *                        01 = Valid page
     91  1.1  gwr  *                        1x = Invalid code for a page descriptor.
     92  1.1  gwr  */
     93  1.1  gwr struct iommu_pde_struct {
     94  1.1  gwr 	union {
     95  1.1  gwr 		struct {
     96  1.1  gwr 			u_int	pa:19;		/* Physical Address  */
     97  1.1  gwr 			u_int	unused:6;	/* Unused bits       */
     98  1.1  gwr 			u_int	ci:1;		/* Cache Inhibit     */
     99  1.1  gwr 			u_int	bx:1;		/* Full Block Xfer   */
    100  1.1  gwr 			u_int	m:1;		/* Modified bit      */
    101  1.1  gwr 			u_int	u:1;		/* Used bit          */
    102  1.1  gwr 			u_int	wp:1;		/* Write Protect bit */
    103  1.1  gwr 			u_int	dt:2;		/* Descriptor type   */
    104  1.1  gwr 			/* Masks for the above fields. */
    105  1.1  gwr #define	IOMMU_PDE_PA		0xFFFFE000
    106  1.1  gwr #define	IOMMU_PDE_UNUSED	0x00001F80
    107  1.1  gwr #define	IOMMU_PDE_CI		0x00000040
    108  1.1  gwr #define	IOMMU_PDE_BX		0x00000020
    109  1.1  gwr #define	IOMMU_PDE_M		0x00000010
    110  1.1  gwr #define	IOMMU_PDE_USED		0x00000008
    111  1.1  gwr #define	IOMMU_PDE_WP		0x00000004
    112  1.1  gwr #define IOMMU_PDE_DT		0x00000003
    113  1.1  gwr 			/* The descriptor types */
    114  1.1  gwr #define	IOMMU_PDE_DT_INVALID	0x00000000	/* Invalid page      */
    115  1.1  gwr #define	IOMMU_PDE_DT_VALID	0x00000001	/* Valid page        */
    116  1.1  gwr 		} stc;
    117  1.1  gwr 		u_int32_t	raw;	/* For unstructured access to the above */
    118  1.1  gwr 	} addr;
    119  1.1  gwr };
    120  1.1  gwr typedef struct iommu_pde_struct iommu_pde_t;
    121  1.1  gwr 
    122  1.1  gwr /* Constants */
    123  1.1  gwr #define	IOMMU_PAGE_SHIFT	13
    124  1.1  gwr 
    125  1.1  gwr /* Useful macros */
    126  1.1  gwr #define	IOMMU_PA_PDE(pde)	((pde).addr.raw & IOMMU_PDE_PA)
    127  1.1  gwr #define	IOMMU_VALID_DT(pde)	((pde).addr.raw & IOMMU_PDE_DT)	/* X1 */
    128  1.1  gwr #define IOMMU_BTOP(pa)		(((u_int) pa) >> IOMMU_PAGE_SHIFT)
    129  1.1  gwr 
    130  1.1  gwr /* X1: This macro will incorrectly report the validity for entries which contain
    131  1.1  gwr  * codes that are invalid.  (Do not confuse this with the code for 'invalid entry',
    132  1.1  gwr  * which means that the descriptor is properly formed, but just not used.)
    133  1.1  gwr  */
    134  1.1  gwr 
    135  1.1  gwr /* Constants for the I/O mapper as used in the sun3x */
    136  1.1  gwr #define	IOMMU_NENT	2048	/* Number of entries in the map */
    137  1.1  gwr 
    138  1.1  gwr /* Interfaces for manipulating the I/O mapper */
    139  1.1  gwr void iommu_enter __P((u_int32_t va, u_int32_t pa));
    140  1.1  gwr void iommu_remove __P((u_int32_t va, u_int32_t len));
    141  1.1  gwr 
    142  1.1  gwr #endif	/* _SUN3X_IOMMU_H */
    143