vio.h 3.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
/*
 * IBM PowerPC Virtual I/O Infrastructure Support.
 *
4 5 6
 * Copyright (c) 2003 IBM Corp.
 *  Dave Engebretsen engebret@us.ibm.com
 *  Santiago Leon santil@us.ibm.com
L
Linus Torvalds 已提交
7
 *
8 9 10 11
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
L
Linus Torvalds 已提交
12 13
 */

14 15
#ifndef _ASM_POWERPC_VIO_H
#define _ASM_POWERPC_VIO_H
16
#ifdef __KERNEL__
L
Linus Torvalds 已提交
17 18 19 20 21

#include <linux/init.h>
#include <linux/errno.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
22
#include <linux/mod_devicetable.h>
S
Stephen Rothwell 已提交
23

L
Linus Torvalds 已提交
24 25
#include <asm/hvcall.h>
#include <asm/scatterlist.h>
S
Stephen Rothwell 已提交
26 27

/*
L
Linus Torvalds 已提交
28 29
 * Architecture-specific constants for drivers to
 * extract attributes of the device using vio_get_attribute()
S
Stephen Rothwell 已提交
30
 */
L
Linus Torvalds 已提交
31 32 33 34 35 36 37 38 39 40 41
#define VETH_MAC_ADDR "local-mac-address"
#define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters"

/* End architecture-specific constants */

#define h_vio_signal(ua, mode) \
  plpar_hcall_norets(H_VIO_SIGNAL, ua, mode)

#define VIO_IRQ_DISABLE		0UL
#define VIO_IRQ_ENABLE		1UL

42 43 44 45 46
/*
 * VIO CMO minimum entitlement for all devices and spare entitlement
 */
#define VIO_CMO_MIN_ENT 1562624

L
Linus Torvalds 已提交
47 48
struct iommu_table;

49 50 51 52 53 54 55
/**
 * vio_dev - This structure is used to describe virtual I/O devices.
 *
 * @desired: set from return of driver's get_desired_dma() function
 * @entitled: bytes of IO data that has been reserved for this device.
 * @allocated: bytes of IO data currently in use by the device.
 * @allocs_failed: number of DMA failures due to insufficient entitlement.
S
Stephen Rothwell 已提交
56 57
 */
struct vio_dev {
58 59
	const char *name;
	const char *type;
S
Stephen Rothwell 已提交
60 61
	uint32_t unit_address;
	unsigned int irq;
62 63 64 65 66 67
	struct {
		size_t desired;
		size_t entitled;
		size_t allocated;
		atomic_t allocs_failed;
	} cmo;
S
Stephen Rothwell 已提交
68 69
	struct device dev;
};
L
Linus Torvalds 已提交
70 71

struct vio_driver {
72
	const char *name;
S
Stephen Rothwell 已提交
73 74 75
	const struct vio_device_id *id_table;
	int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
	int (*remove)(struct vio_dev *dev);
76 77 78 79
	/* A driver must have a get_desired_dma() function to
	 * be loaded in a CMO environment if it uses DMA.
	 */
	unsigned long (*get_desired_dma)(struct vio_dev *dev);
80
	const struct dev_pm_ops *pm;
L
Linus Torvalds 已提交
81 82 83
	struct device_driver driver;
};

84 85 86 87 88 89 90
extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
				 const char *mod_name);
/*
 * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
 */
#define vio_register_driver(driver)		\
	__vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
S
Stephen Rothwell 已提交
91 92
extern void vio_unregister_driver(struct vio_driver *drv);

93 94 95
extern int vio_cmo_entitlement_update(size_t);
extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired);

S
Stephen Rothwell 已提交
96 97 98 99
extern void __devinit vio_unregister_device(struct vio_dev *dev);

struct device_node;

100
extern struct vio_dev *vio_register_device_node(
S
Stephen Rothwell 已提交
101
		struct device_node *node_vdev);
102
extern const void *vio_get_attribute(struct vio_dev *vdev, char *which,
S
Stephen Rothwell 已提交
103
		int *length);
104 105
#ifdef CONFIG_PPC_PSERIES
extern struct vio_dev *vio_find_node(struct device_node *vnode);
S
Stephen Rothwell 已提交
106 107
extern int vio_enable_interrupts(struct vio_dev *dev);
extern int vio_disable_interrupts(struct vio_dev *dev);
108 109 110 111 112
#else
static inline int vio_enable_interrupts(struct vio_dev *dev)
{
	return 0;
}
S
Stephen Rothwell 已提交
113 114
#endif

L
Linus Torvalds 已提交
115 116 117 118 119 120 121 122 123 124
static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
{
	return container_of(drv, struct vio_driver, driver);
}

static inline struct vio_dev *to_vio_dev(struct device *dev)
{
	return container_of(dev, struct vio_dev, dev);
}

125
#endif /* __KERNEL__ */
126
#endif /* _ASM_POWERPC_VIO_H */