Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: sbus.h,v 1.22 2000/02/18 13:50:50 davem Exp $ |
| 2 | * sbus.h: Defines for the Sun SBus. |
| 3 | * |
| 4 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) |
| 5 | */ |
| 6 | |
| 7 | #ifndef _SPARC_SBUS_H |
| 8 | #define _SPARC_SBUS_H |
| 9 | |
| 10 | #include <linux/dma-mapping.h> |
| 11 | #include <linux/ioport.h> |
| 12 | |
| 13 | #include <asm/oplib.h> |
| 14 | /* #include <asm/iommu.h> */ /* Unused since we use opaque iommu (|io-unit) */ |
| 15 | #include <asm/scatterlist.h> |
| 16 | |
| 17 | /* We scan which devices are on the SBus using the PROM node device |
| 18 | * tree. SBus devices are described in two different ways. You can |
| 19 | * either get an absolute address at which to access the device, or |
| 20 | * you can get a SBus 'slot' number and an offset within that slot. |
| 21 | */ |
| 22 | |
| 23 | /* The base address at which to calculate device OBIO addresses. */ |
| 24 | #define SUN_SBUS_BVADDR 0xf8000000 |
| 25 | #define SBUS_OFF_MASK 0x01ffffff |
| 26 | |
| 27 | /* These routines are used to calculate device address from slot |
| 28 | * numbers + offsets, and vice versa. |
| 29 | */ |
| 30 | |
| 31 | extern __inline__ unsigned long sbus_devaddr(int slotnum, unsigned long offset) |
| 32 | { |
| 33 | return (unsigned long) (SUN_SBUS_BVADDR+((slotnum)<<25)+(offset)); |
| 34 | } |
| 35 | |
| 36 | extern __inline__ int sbus_dev_slot(unsigned long dev_addr) |
| 37 | { |
| 38 | return (int) (((dev_addr)-SUN_SBUS_BVADDR)>>25); |
| 39 | } |
| 40 | |
| 41 | struct sbus_bus; |
| 42 | |
| 43 | /* Linux SBUS device tables */ |
| 44 | struct sbus_dev { |
| 45 | struct sbus_bus *bus; /* Back ptr to sbus */ |
| 46 | struct sbus_dev *next; /* next device on this SBus or null */ |
| 47 | struct sbus_dev *child; /* For ledma and espdma on sun4m */ |
| 48 | struct sbus_dev *parent; /* Parent device if not toplevel */ |
| 49 | int prom_node; /* PROM device tree node for this device */ |
| 50 | char prom_name[64]; /* PROM device name */ |
| 51 | int slot; |
| 52 | |
| 53 | struct resource resource[PROMREG_MAX]; |
| 54 | |
| 55 | struct linux_prom_registers reg_addrs[PROMREG_MAX]; |
| 56 | int num_registers, ranges_applied; |
| 57 | |
| 58 | struct linux_prom_ranges device_ranges[PROMREG_MAX]; |
| 59 | int num_device_ranges; |
| 60 | |
| 61 | unsigned int irqs[4]; |
| 62 | int num_irqs; |
| 63 | }; |
| 64 | |
| 65 | /* This struct describes the SBus(s) found on this machine. */ |
| 66 | struct sbus_bus { |
| 67 | void *iommu; /* Opaque IOMMU cookie */ |
| 68 | struct sbus_dev *devices; /* Link to devices on this SBus */ |
| 69 | struct sbus_bus *next; /* next SBus, if more than one SBus */ |
| 70 | int prom_node; /* PROM device tree node for this SBus */ |
| 71 | char prom_name[64]; /* Usually "sbus" or "sbi" */ |
| 72 | int clock_freq; |
| 73 | |
| 74 | struct linux_prom_ranges sbus_ranges[PROMREG_MAX]; |
| 75 | int num_sbus_ranges; |
| 76 | |
| 77 | int devid; |
| 78 | int board; |
| 79 | }; |
| 80 | |
| 81 | extern struct sbus_bus *sbus_root; |
| 82 | |
| 83 | extern __inline__ int |
| 84 | sbus_is_slave(struct sbus_dev *dev) |
| 85 | { |
| 86 | /* XXX Have to write this for sun4c's */ |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /* Device probing routines could find these handy */ |
| 91 | #define for_each_sbus(bus) \ |
| 92 | for((bus) = sbus_root; (bus); (bus)=(bus)->next) |
| 93 | |
| 94 | #define for_each_sbusdev(device, bus) \ |
| 95 | for((device) = (bus)->devices; (device); (device)=(device)->next) |
| 96 | |
| 97 | #define for_all_sbusdev(device, bus) \ |
| 98 | for ((bus) = sbus_root; (bus); (bus) = (bus)->next) \ |
| 99 | for ((device) = (bus)->devices; (device); (device) = (device)->next) |
| 100 | |
| 101 | /* Driver DVMA interfaces. */ |
| 102 | #define sbus_can_dma_64bit(sdev) (0) /* actually, sparc_cpu_model==sun4d */ |
| 103 | #define sbus_can_burst64(sdev) (0) /* actually, sparc_cpu_model==sun4d */ |
| 104 | extern void sbus_set_sbus64(struct sbus_dev *, int); |
| 105 | |
| 106 | /* These yield IOMMU mappings in consistent mode. */ |
| 107 | extern void *sbus_alloc_consistent(struct sbus_dev *, long, u32 *dma_addrp); |
| 108 | extern void sbus_free_consistent(struct sbus_dev *, long, void *, u32); |
| 109 | void prom_adjust_ranges(struct linux_prom_ranges *, int, |
| 110 | struct linux_prom_ranges *, int); |
| 111 | |
| 112 | #define SBUS_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL |
| 113 | #define SBUS_DMA_TODEVICE DMA_TO_DEVICE |
| 114 | #define SBUS_DMA_FROMDEVICE DMA_FROM_DEVICE |
| 115 | #define SBUS_DMA_NONE DMA_NONE |
| 116 | |
| 117 | /* All the rest use streaming mode mappings. */ |
| 118 | extern dma_addr_t sbus_map_single(struct sbus_dev *, void *, size_t, int); |
| 119 | extern void sbus_unmap_single(struct sbus_dev *, dma_addr_t, size_t, int); |
| 120 | extern int sbus_map_sg(struct sbus_dev *, struct scatterlist *, int, int); |
| 121 | extern void sbus_unmap_sg(struct sbus_dev *, struct scatterlist *, int, int); |
| 122 | |
| 123 | /* Finally, allow explicit synchronization of streamable mappings. */ |
| 124 | extern void sbus_dma_sync_single_for_cpu(struct sbus_dev *, dma_addr_t, size_t, int); |
| 125 | #define sbus_dma_sync_single sbus_dma_sync_single_for_cpu |
| 126 | extern void sbus_dma_sync_single_for_device(struct sbus_dev *, dma_addr_t, size_t, int); |
| 127 | extern void sbus_dma_sync_sg_for_cpu(struct sbus_dev *, struct scatterlist *, int, int); |
| 128 | #define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu |
| 129 | extern void sbus_dma_sync_sg_for_device(struct sbus_dev *, struct scatterlist *, int, int); |
| 130 | |
| 131 | /* Eric Brower (ebrower@usa.net) |
| 132 | * Translate SBus interrupt levels to ino values-- |
| 133 | * this is used when converting sbus "interrupts" OBP |
| 134 | * node values to "intr" node values, and is platform |
| 135 | * dependent. If only we could call OBP with |
| 136 | * "sbus-intr>cpu (sbint -- ino)" from kernel... |
| 137 | * See .../drivers/sbus/sbus.c for details. |
| 138 | */ |
| 139 | BTFIXUPDEF_CALL(unsigned int, sbint_to_irq, struct sbus_dev *sdev, unsigned int) |
| 140 | #define sbint_to_irq(sdev, sbint) BTFIXUP_CALL(sbint_to_irq)(sdev, sbint) |
| 141 | |
| 142 | #endif /* !(_SPARC_SBUS_H) */ |