blob: 7efd49d31bb8a55a71f9ce9d07dcdf3a2a2e920f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: sbus.h,v 1.14 2000/02/18 13:50:55 davem Exp $
2 * sbus.h: Defines for the Sun SBus.
3 *
4 * Copyright (C) 1996, 1999 David S. Miller (davem@redhat.com)
5 */
6
7#ifndef _SPARC64_SBUS_H
8#define _SPARC64_SBUS_H
9
10#include <linux/dma-mapping.h>
11#include <linux/ioport.h>
12
13#include <asm/oplib.h>
David S. Miller576c3522006-06-23 15:55:45 -070014#include <asm/prom.h>
15#include <asm/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/iommu.h>
17#include <asm/scatterlist.h>
18
19/* We scan which devices are on the SBus using the PROM node device
20 * tree. SBus devices are described in two different ways. You can
21 * either get an absolute address at which to access the device, or
22 * you can get a SBus 'slot' number and an offset within that slot.
23 */
24
25/* The base address at which to calculate device OBIO addresses. */
26#define SUN_SBUS_BVADDR 0x00000000
27#define SBUS_OFF_MASK 0x0fffffff
28
29/* These routines are used to calculate device address from slot
30 * numbers + offsets, and vice versa.
31 */
32
33static __inline__ unsigned long sbus_devaddr(int slotnum, unsigned long offset)
34{
35 return (unsigned long) (SUN_SBUS_BVADDR+((slotnum)<<28)+(offset));
36}
37
38static __inline__ int sbus_dev_slot(unsigned long dev_addr)
39{
40 return (int) (((dev_addr)-SUN_SBUS_BVADDR)>>28);
41}
42
43struct sbus_bus;
44
45/* Linux SBUS device tables */
46struct sbus_dev {
David S. Miller576c3522006-06-23 15:55:45 -070047 struct of_device ofdev;
48 struct sbus_bus *bus;
49 struct sbus_dev *next;
50 struct sbus_dev *child;
51 struct sbus_dev *parent;
52 int prom_node;
53 char prom_name[64];
54 int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56 struct resource resource[PROMREG_MAX];
57
58 struct linux_prom_registers reg_addrs[PROMREG_MAX];
David S. Miller576c3522006-06-23 15:55:45 -070059 int num_registers;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 struct linux_prom_ranges device_ranges[PROMREG_MAX];
62 int num_device_ranges;
63
64 unsigned int irqs[4];
65 int num_irqs;
66};
David S. Miller576c3522006-06-23 15:55:45 -070067#define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/* This struct describes the SBus(s) found on this machine. */
70struct sbus_bus {
David S. Miller576c3522006-06-23 15:55:45 -070071 struct of_device ofdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 void *iommu; /* Opaque IOMMU cookie */
73 struct sbus_dev *devices; /* Tree of SBUS devices */
74 struct sbus_bus *next; /* Next SBUS in system */
75 int prom_node; /* OBP node of SBUS */
76 char prom_name[64]; /* Usually "sbus" or "sbi" */
77 int clock_freq;
78
79 struct linux_prom_ranges sbus_ranges[PROMREG_MAX];
80 int num_sbus_ranges;
81
82 int portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
David S. Miller576c3522006-06-23 15:55:45 -070084#define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86extern struct sbus_bus *sbus_root;
87
88/* Device probing routines could find these handy */
89#define for_each_sbus(bus) \
90 for((bus) = sbus_root; (bus); (bus)=(bus)->next)
91
92#define for_each_sbusdev(device, bus) \
93 for((device) = (bus)->devices; (device); (device)=(device)->next)
94
95#define for_all_sbusdev(device, bus) \
96 for ((bus) = sbus_root; (bus); (bus) = (bus)->next) \
97 for ((device) = (bus)->devices; (device); (device) = (device)->next)
98
99/* Driver DVMA interfaces. */
100#define sbus_can_dma_64bit(sdev) (1)
101#define sbus_can_burst64(sdev) (1)
102extern void sbus_set_sbus64(struct sbus_dev *, int);
David S. Miller8fae0972006-06-20 15:23:28 -0700103extern void sbus_fill_device_irq(struct sbus_dev *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105/* These yield IOMMU mappings in consistent mode. */
106extern void *sbus_alloc_consistent(struct sbus_dev *, size_t, dma_addr_t *dma_addrp);
107extern void sbus_free_consistent(struct sbus_dev *, size_t, void *, dma_addr_t);
108
109#define SBUS_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL
110#define SBUS_DMA_TODEVICE DMA_TO_DEVICE
111#define SBUS_DMA_FROMDEVICE DMA_FROM_DEVICE
112#define SBUS_DMA_NONE DMA_NONE
113
114/* All the rest use streaming mode mappings. */
115extern dma_addr_t sbus_map_single(struct sbus_dev *, void *, size_t, int);
116extern void sbus_unmap_single(struct sbus_dev *, dma_addr_t, size_t, int);
117extern int sbus_map_sg(struct sbus_dev *, struct scatterlist *, int, int);
118extern void sbus_unmap_sg(struct sbus_dev *, struct scatterlist *, int, int);
119
120/* Finally, allow explicit synchronization of streamable mappings. */
121extern void sbus_dma_sync_single_for_cpu(struct sbus_dev *, dma_addr_t, size_t, int);
122#define sbus_dma_sync_single sbus_dma_sync_single_for_cpu
123extern void sbus_dma_sync_single_for_device(struct sbus_dev *, dma_addr_t, size_t, int);
124extern void sbus_dma_sync_sg_for_cpu(struct sbus_dev *, struct scatterlist *, int, int);
125#define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu
126extern void sbus_dma_sync_sg_for_device(struct sbus_dev *, struct scatterlist *, int, int);
127
David S. Miller576c3522006-06-23 15:55:45 -0700128extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *);
129extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *);
130extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *);
131extern int sbus_arch_preinit(void);
132extern void sbus_arch_postinit(void);
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif /* !(_SPARC64_SBUS_H) */