1/*
2 * Machine vector for IA-64.
3 *
4 * Copyright (C) 1999 Silicon Graphics, Inc.
5 * Copyright (C) Srinivasa Thirumalachar <sprasad@engr.sgi.com>
6 * Copyright (C) Vijay Chander <vijay@engr.sgi.com>
7 * Copyright (C) 1999-2001, 2003-2004 Hewlett-Packard Co.
8 *	David Mosberger-Tang <davidm@hpl.hp.com>
9 */
10#ifndef _ASM_IA64_MACHVEC_H
11#define _ASM_IA64_MACHVEC_H
12
13#include <linux/types.h>
14
15/* forward declarations: */
16struct device;
17struct pt_regs;
18struct scatterlist;
19struct page;
20struct mm_struct;
21struct pci_bus;
22struct task_struct;
23struct pci_dev;
24struct msi_desc;
25
26typedef void ia64_mv_setup_t (char **);
27typedef void ia64_mv_cpu_init_t (void);
28typedef void ia64_mv_irq_init_t (void);
29typedef void ia64_mv_send_ipi_t (int, int, int, int);
30typedef void ia64_mv_timer_interrupt_t (int, void *);
31typedef void ia64_mv_global_tlb_purge_t (struct mm_struct *, unsigned long, unsigned long, unsigned long);
32typedef void ia64_mv_tlb_migrate_finish_t (struct mm_struct *);
33typedef unsigned int ia64_mv_local_vector_to_irq (u8);
34typedef char *ia64_mv_pci_get_legacy_mem_t (struct pci_bus *);
35typedef int ia64_mv_pci_legacy_read_t (struct pci_bus *, u16 port, u32 *val,
36				       u8 size);
37typedef int ia64_mv_pci_legacy_write_t (struct pci_bus *, u16 port, u32 val,
38					u8 size);
39typedef void ia64_mv_migrate_t(struct task_struct * task);
40typedef void ia64_mv_pci_fixup_bus_t (struct pci_bus *);
41typedef void ia64_mv_kernel_launch_event_t(void);
42
43/* DMA-mapping interface: */
44typedef void ia64_mv_dma_init (void);
45typedef void *ia64_mv_dma_alloc_coherent (struct device *, size_t, dma_addr_t *, gfp_t);
46typedef void ia64_mv_dma_free_coherent (struct device *, size_t, void *, dma_addr_t);
47typedef dma_addr_t ia64_mv_dma_map_single (struct device *, void *, size_t, int);
48typedef void ia64_mv_dma_unmap_single (struct device *, dma_addr_t, size_t, int);
49typedef int ia64_mv_dma_map_sg (struct device *, struct scatterlist *, int, int);
50typedef void ia64_mv_dma_unmap_sg (struct device *, struct scatterlist *, int, int);
51typedef void ia64_mv_dma_sync_single_for_cpu (struct device *, dma_addr_t, size_t, int);
52typedef void ia64_mv_dma_sync_sg_for_cpu (struct device *, struct scatterlist *, int, int);
53typedef void ia64_mv_dma_sync_single_for_device (struct device *, dma_addr_t, size_t, int);
54typedef void ia64_mv_dma_sync_sg_for_device (struct device *, struct scatterlist *, int, int);
55typedef int ia64_mv_dma_mapping_error (dma_addr_t dma_addr);
56typedef int ia64_mv_dma_supported (struct device *, u64);
57
58/*
59 * WARNING: The legacy I/O space is _architected_.  Platforms are
60 * expected to follow this architected model (see Section 10.7 in the
61 * IA-64 Architecture Software Developer's Manual).  Unfortunately,
62 * some broken machines do not follow that model, which is why we have
63 * to make the inX/outX operations part of the machine vector.
64 * Platform designers should follow the architected model whenever
65 * possible.
66 */
67typedef unsigned int ia64_mv_inb_t (unsigned long);
68typedef unsigned int ia64_mv_inw_t (unsigned long);
69typedef unsigned int ia64_mv_inl_t (unsigned long);
70typedef void ia64_mv_outb_t (unsigned char, unsigned long);
71typedef void ia64_mv_outw_t (unsigned short, unsigned long);
72typedef void ia64_mv_outl_t (unsigned int, unsigned long);
73typedef void ia64_mv_mmiowb_t (void);
74typedef unsigned char ia64_mv_readb_t (const volatile void __iomem *);
75typedef unsigned short ia64_mv_readw_t (const volatile void __iomem *);
76typedef unsigned int ia64_mv_readl_t (const volatile void __iomem *);
77typedef unsigned long ia64_mv_readq_t (const volatile void __iomem *);
78typedef unsigned char ia64_mv_readb_relaxed_t (const volatile void __iomem *);
79typedef unsigned short ia64_mv_readw_relaxed_t (const volatile void __iomem *);
80typedef unsigned int ia64_mv_readl_relaxed_t (const volatile void __iomem *);
81typedef unsigned long ia64_mv_readq_relaxed_t (const volatile void __iomem *);
82
83typedef int ia64_mv_setup_msi_irq_t (struct pci_dev *pdev, struct msi_desc *);
84typedef void ia64_mv_teardown_msi_irq_t (unsigned int irq);
85
86static inline void
87machvec_noop (void)
88{
89}
90
91static inline void
92machvec_noop_mm (struct mm_struct *mm)
93{
94}
95
96static inline void
97machvec_noop_task (struct task_struct *task)
98{
99}
100
101static inline void
102machvec_noop_bus (struct pci_bus *bus)
103{
104}
105
106extern void machvec_setup (char **);
107extern void machvec_timer_interrupt (int, void *);
108extern void machvec_dma_sync_single (struct device *, dma_addr_t, size_t, int);
109extern void machvec_dma_sync_sg (struct device *, struct scatterlist *, int, int);
110extern void machvec_tlb_migrate_finish (struct mm_struct *);
111
112# if defined(CONFIG_IA64_HP_SIM)
113#  include <asm/machvec_hpsim.h>
114# elif defined(CONFIG_IA64_DIG)
115#  include <asm/machvec_dig.h>
116# elif defined(CONFIG_IA64_HP_ZX1)
117#  include <asm/machvec_hpzx1.h>
118# elif defined(CONFIG_IA64_HP_ZX1_SWIOTLB)
119#  include <asm/machvec_hpzx1_swiotlb.h>
120# elif defined(CONFIG_IA64_SGI_SN2)
121#  include <asm/machvec_sn2.h>
122# elif defined(CONFIG_IA64_GENERIC)
123
124# ifdef MACHVEC_PLATFORM_HEADER
125#  include MACHVEC_PLATFORM_HEADER
126# else
127#  define platform_name		ia64_mv.name
128#  define platform_setup	ia64_mv.setup
129#  define platform_cpu_init	ia64_mv.cpu_init
130#  define platform_irq_init	ia64_mv.irq_init
131#  define platform_send_ipi	ia64_mv.send_ipi
132#  define platform_timer_interrupt	ia64_mv.timer_interrupt
133#  define platform_global_tlb_purge	ia64_mv.global_tlb_purge
134#  define platform_tlb_migrate_finish	ia64_mv.tlb_migrate_finish
135#  define platform_dma_init		ia64_mv.dma_init
136#  define platform_dma_alloc_coherent	ia64_mv.dma_alloc_coherent
137#  define platform_dma_free_coherent	ia64_mv.dma_free_coherent
138#  define platform_dma_map_single	ia64_mv.dma_map_single
139#  define platform_dma_unmap_single	ia64_mv.dma_unmap_single
140#  define platform_dma_map_sg		ia64_mv.dma_map_sg
141#  define platform_dma_unmap_sg		ia64_mv.dma_unmap_sg
142#  define platform_dma_sync_single_for_cpu ia64_mv.dma_sync_single_for_cpu
143#  define platform_dma_sync_sg_for_cpu	ia64_mv.dma_sync_sg_for_cpu
144#  define platform_dma_sync_single_for_device ia64_mv.dma_sync_single_for_device
145#  define platform_dma_sync_sg_for_device ia64_mv.dma_sync_sg_for_device
146#  define platform_dma_mapping_error		ia64_mv.dma_mapping_error
147#  define platform_dma_supported	ia64_mv.dma_supported
148#  define platform_local_vector_to_irq	ia64_mv.local_vector_to_irq
149#  define platform_pci_get_legacy_mem	ia64_mv.pci_get_legacy_mem
150#  define platform_pci_legacy_read	ia64_mv.pci_legacy_read
151#  define platform_pci_legacy_write	ia64_mv.pci_legacy_write
152#  define platform_inb		ia64_mv.inb
153#  define platform_inw		ia64_mv.inw
154#  define platform_inl		ia64_mv.inl
155#  define platform_outb		ia64_mv.outb
156#  define platform_outw		ia64_mv.outw
157#  define platform_outl		ia64_mv.outl
158#  define platform_mmiowb	ia64_mv.mmiowb
159#  define platform_readb        ia64_mv.readb
160#  define platform_readw        ia64_mv.readw
161#  define platform_readl        ia64_mv.readl
162#  define platform_readq        ia64_mv.readq
163#  define platform_readb_relaxed        ia64_mv.readb_relaxed
164#  define platform_readw_relaxed        ia64_mv.readw_relaxed
165#  define platform_readl_relaxed        ia64_mv.readl_relaxed
166#  define platform_readq_relaxed        ia64_mv.readq_relaxed
167#  define platform_migrate		ia64_mv.migrate
168#  define platform_setup_msi_irq	ia64_mv.setup_msi_irq
169#  define platform_teardown_msi_irq	ia64_mv.teardown_msi_irq
170#  define platform_pci_fixup_bus	ia64_mv.pci_fixup_bus
171#  define platform_kernel_launch_event	ia64_mv.kernel_launch_event
172# endif
173
174/* __attribute__((__aligned__(16))) is required to make size of the
175 * structure multiple of 16 bytes.
176 * This will fillup the holes created because of section 3.3.1 in
177 * Software Conventions guide.
178 */
179struct ia64_machine_vector {
180	const char *name;
181	ia64_mv_setup_t *setup;
182	ia64_mv_cpu_init_t *cpu_init;
183	ia64_mv_irq_init_t *irq_init;
184	ia64_mv_send_ipi_t *send_ipi;
185	ia64_mv_timer_interrupt_t *timer_interrupt;
186	ia64_mv_global_tlb_purge_t *global_tlb_purge;
187	ia64_mv_tlb_migrate_finish_t *tlb_migrate_finish;
188	ia64_mv_dma_init *dma_init;
189	ia64_mv_dma_alloc_coherent *dma_alloc_coherent;
190	ia64_mv_dma_free_coherent *dma_free_coherent;
191	ia64_mv_dma_map_single *dma_map_single;
192	ia64_mv_dma_unmap_single *dma_unmap_single;
193	ia64_mv_dma_map_sg *dma_map_sg;
194	ia64_mv_dma_unmap_sg *dma_unmap_sg;
195	ia64_mv_dma_sync_single_for_cpu *dma_sync_single_for_cpu;
196	ia64_mv_dma_sync_sg_for_cpu *dma_sync_sg_for_cpu;
197	ia64_mv_dma_sync_single_for_device *dma_sync_single_for_device;
198	ia64_mv_dma_sync_sg_for_device *dma_sync_sg_for_device;
199	ia64_mv_dma_mapping_error *dma_mapping_error;
200	ia64_mv_dma_supported *dma_supported;
201	ia64_mv_local_vector_to_irq *local_vector_to_irq;
202	ia64_mv_pci_get_legacy_mem_t *pci_get_legacy_mem;
203	ia64_mv_pci_legacy_read_t *pci_legacy_read;
204	ia64_mv_pci_legacy_write_t *pci_legacy_write;
205	ia64_mv_inb_t *inb;
206	ia64_mv_inw_t *inw;
207	ia64_mv_inl_t *inl;
208	ia64_mv_outb_t *outb;
209	ia64_mv_outw_t *outw;
210	ia64_mv_outl_t *outl;
211	ia64_mv_mmiowb_t *mmiowb;
212	ia64_mv_readb_t *readb;
213	ia64_mv_readw_t *readw;
214	ia64_mv_readl_t *readl;
215	ia64_mv_readq_t *readq;
216	ia64_mv_readb_relaxed_t *readb_relaxed;
217	ia64_mv_readw_relaxed_t *readw_relaxed;
218	ia64_mv_readl_relaxed_t *readl_relaxed;
219	ia64_mv_readq_relaxed_t *readq_relaxed;
220	ia64_mv_migrate_t *migrate;
221	ia64_mv_setup_msi_irq_t *setup_msi_irq;
222	ia64_mv_teardown_msi_irq_t *teardown_msi_irq;
223	ia64_mv_pci_fixup_bus_t *pci_fixup_bus;
224	ia64_mv_kernel_launch_event_t *kernel_launch_event;
225} __attribute__((__aligned__(16))); /* align attrib? see above comment */
226
227#define MACHVEC_INIT(name)			\
228{						\
229	#name,					\
230	platform_setup,				\
231	platform_cpu_init,			\
232	platform_irq_init,			\
233	platform_send_ipi,			\
234	platform_timer_interrupt,		\
235	platform_global_tlb_purge,		\
236	platform_tlb_migrate_finish,		\
237	platform_dma_init,			\
238	platform_dma_alloc_coherent,		\
239	platform_dma_free_coherent,		\
240	platform_dma_map_single,		\
241	platform_dma_unmap_single,		\
242	platform_dma_map_sg,			\
243	platform_dma_unmap_sg,			\
244	platform_dma_sync_single_for_cpu,	\
245	platform_dma_sync_sg_for_cpu,		\
246	platform_dma_sync_single_for_device,	\
247	platform_dma_sync_sg_for_device,	\
248	platform_dma_mapping_error,			\
249	platform_dma_supported,			\
250	platform_local_vector_to_irq,		\
251	platform_pci_get_legacy_mem,		\
252	platform_pci_legacy_read,		\
253	platform_pci_legacy_write,		\
254	platform_inb,				\
255	platform_inw,				\
256	platform_inl,				\
257	platform_outb,				\
258	platform_outw,				\
259	platform_outl,				\
260	platform_mmiowb,			\
261	platform_readb,				\
262	platform_readw,				\
263	platform_readl,				\
264	platform_readq,				\
265	platform_readb_relaxed,			\
266	platform_readw_relaxed,			\
267	platform_readl_relaxed,			\
268	platform_readq_relaxed,			\
269	platform_migrate,			\
270	platform_setup_msi_irq,			\
271	platform_teardown_msi_irq,		\
272	platform_pci_fixup_bus,			\
273	platform_kernel_launch_event            \
274}
275
276extern struct ia64_machine_vector ia64_mv;
277extern void machvec_init (const char *name);
278
279# else
280#  error Unknown configuration.  Update asm-ia64/machvec.h.
281# endif /* CONFIG_IA64_GENERIC */
282
283/*
284 * Declare default routines which aren't declared anywhere else:
285 */
286extern ia64_mv_dma_init			swiotlb_init;
287extern ia64_mv_dma_alloc_coherent	swiotlb_alloc_coherent;
288extern ia64_mv_dma_free_coherent	swiotlb_free_coherent;
289extern ia64_mv_dma_map_single		swiotlb_map_single;
290extern ia64_mv_dma_unmap_single		swiotlb_unmap_single;
291extern ia64_mv_dma_map_sg		swiotlb_map_sg;
292extern ia64_mv_dma_unmap_sg		swiotlb_unmap_sg;
293extern ia64_mv_dma_sync_single_for_cpu	swiotlb_sync_single_for_cpu;
294extern ia64_mv_dma_sync_sg_for_cpu	swiotlb_sync_sg_for_cpu;
295extern ia64_mv_dma_sync_single_for_device swiotlb_sync_single_for_device;
296extern ia64_mv_dma_sync_sg_for_device	swiotlb_sync_sg_for_device;
297extern ia64_mv_dma_mapping_error	swiotlb_dma_mapping_error;
298extern ia64_mv_dma_supported		swiotlb_dma_supported;
299
300/*
301 * Define default versions so we can extend machvec for new platforms without having
302 * to update the machvec files for all existing platforms.
303 */
304#ifndef platform_setup
305# define platform_setup			machvec_setup
306#endif
307#ifndef platform_cpu_init
308# define platform_cpu_init		machvec_noop
309#endif
310#ifndef platform_irq_init
311# define platform_irq_init		machvec_noop
312#endif
313
314#ifndef platform_send_ipi
315# define platform_send_ipi		ia64_send_ipi	/* default to architected version */
316#endif
317#ifndef platform_timer_interrupt
318# define platform_timer_interrupt 	machvec_timer_interrupt
319#endif
320#ifndef platform_global_tlb_purge
321# define platform_global_tlb_purge	ia64_global_tlb_purge /* default to architected version */
322#endif
323#ifndef platform_tlb_migrate_finish
324# define platform_tlb_migrate_finish	machvec_noop_mm
325#endif
326#ifndef platform_kernel_launch_event
327# define platform_kernel_launch_event	machvec_noop
328#endif
329#ifndef platform_dma_init
330# define platform_dma_init		swiotlb_init
331#endif
332#ifndef platform_dma_alloc_coherent
333# define platform_dma_alloc_coherent	swiotlb_alloc_coherent
334#endif
335#ifndef platform_dma_free_coherent
336# define platform_dma_free_coherent	swiotlb_free_coherent
337#endif
338#ifndef platform_dma_map_single
339# define platform_dma_map_single	swiotlb_map_single
340#endif
341#ifndef platform_dma_unmap_single
342# define platform_dma_unmap_single	swiotlb_unmap_single
343#endif
344#ifndef platform_dma_map_sg
345# define platform_dma_map_sg		swiotlb_map_sg
346#endif
347#ifndef platform_dma_unmap_sg
348# define platform_dma_unmap_sg		swiotlb_unmap_sg
349#endif
350#ifndef platform_dma_sync_single_for_cpu
351# define platform_dma_sync_single_for_cpu	swiotlb_sync_single_for_cpu
352#endif
353#ifndef platform_dma_sync_sg_for_cpu
354# define platform_dma_sync_sg_for_cpu		swiotlb_sync_sg_for_cpu
355#endif
356#ifndef platform_dma_sync_single_for_device
357# define platform_dma_sync_single_for_device	swiotlb_sync_single_for_device
358#endif
359#ifndef platform_dma_sync_sg_for_device
360# define platform_dma_sync_sg_for_device	swiotlb_sync_sg_for_device
361#endif
362#ifndef platform_dma_mapping_error
363# define platform_dma_mapping_error		swiotlb_dma_mapping_error
364#endif
365#ifndef platform_dma_supported
366# define  platform_dma_supported	swiotlb_dma_supported
367#endif
368#ifndef platform_local_vector_to_irq
369# define platform_local_vector_to_irq	__ia64_local_vector_to_irq
370#endif
371#ifndef platform_pci_get_legacy_mem
372# define platform_pci_get_legacy_mem	ia64_pci_get_legacy_mem
373#endif
374#ifndef platform_pci_legacy_read
375# define platform_pci_legacy_read	ia64_pci_legacy_read
376extern int ia64_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size);
377#endif
378#ifndef platform_pci_legacy_write
379# define platform_pci_legacy_write	ia64_pci_legacy_write
380extern int ia64_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size);
381#endif
382#ifndef platform_inb
383# define platform_inb		__ia64_inb
384#endif
385#ifndef platform_inw
386# define platform_inw		__ia64_inw
387#endif
388#ifndef platform_inl
389# define platform_inl		__ia64_inl
390#endif
391#ifndef platform_outb
392# define platform_outb		__ia64_outb
393#endif
394#ifndef platform_outw
395# define platform_outw		__ia64_outw
396#endif
397#ifndef platform_outl
398# define platform_outl		__ia64_outl
399#endif
400#ifndef platform_mmiowb
401# define platform_mmiowb	__ia64_mmiowb
402#endif
403#ifndef platform_readb
404# define platform_readb		__ia64_readb
405#endif
406#ifndef platform_readw
407# define platform_readw		__ia64_readw
408#endif
409#ifndef platform_readl
410# define platform_readl		__ia64_readl
411#endif
412#ifndef platform_readq
413# define platform_readq		__ia64_readq
414#endif
415#ifndef platform_readb_relaxed
416# define platform_readb_relaxed	__ia64_readb_relaxed
417#endif
418#ifndef platform_readw_relaxed
419# define platform_readw_relaxed	__ia64_readw_relaxed
420#endif
421#ifndef platform_readl_relaxed
422# define platform_readl_relaxed	__ia64_readl_relaxed
423#endif
424#ifndef platform_readq_relaxed
425# define platform_readq_relaxed	__ia64_readq_relaxed
426#endif
427#ifndef platform_migrate
428# define platform_migrate machvec_noop_task
429#endif
430#ifndef platform_setup_msi_irq
431# define platform_setup_msi_irq		((ia64_mv_setup_msi_irq_t*)NULL)
432#endif
433#ifndef platform_teardown_msi_irq
434# define platform_teardown_msi_irq	((ia64_mv_teardown_msi_irq_t*)NULL)
435#endif
436#ifndef platform_pci_fixup_bus
437# define platform_pci_fixup_bus	machvec_noop_bus
438#endif
439
440#endif /* _ASM_IA64_MACHVEC_H */
441