Loading...
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * IBM PowerPC Virtual I/O Infrastructure Support.
4 *
5 * Copyright (c) 2003 IBM Corp.
6 * Dave Engebretsen engebret@us.ibm.com
7 * Santiago Leon santil@us.ibm.com
8 */
9
10#ifndef _ASM_POWERPC_VIO_H
11#define _ASM_POWERPC_VIO_H
12#ifdef __KERNEL__
13
14#include <linux/errno.h>
15#include <linux/device.h>
16#include <linux/dma-mapping.h>
17#include <linux/mod_devicetable.h>
18#include <linux/scatterlist.h>
19
20#include <asm/hvcall.h>
21
22/*
23 * Architecture-specific constants for drivers to
24 * extract attributes of the device using vio_get_attribute()
25 */
26#define VETH_MAC_ADDR "local-mac-address"
27#define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters"
28
29/* End architecture-specific constants */
30
31#define h_vio_signal(ua, mode) \
32 plpar_hcall_norets(H_VIO_SIGNAL, ua, mode)
33
34#define VIO_IRQ_DISABLE 0UL
35#define VIO_IRQ_ENABLE 1UL
36
37/*
38 * VIO CMO minimum entitlement for all devices and spare entitlement
39 */
40#define VIO_CMO_MIN_ENT 1562624
41
42extern const struct bus_type vio_bus_type;
43
44struct iommu_table;
45
46/*
47 * Platform Facilities Option (PFO)-specific data
48 */
49
50/* Starting unit address for PFO devices on the VIO BUS */
51#define VIO_BASE_PFO_UA 0x50000000
52
53/**
54 * vio_pfo_op - PFO operation parameters
55 *
56 * @flags: h_call subfunctions and modifiers
57 * @in: Input data block logical real address
58 * @inlen: If non-negative, the length of the input data block. If negative,
59 * the length of the input data descriptor list in bytes.
60 * @out: Output data block logical real address
61 * @outlen: If non-negative, the length of the input data block. If negative,
62 * the length of the input data descriptor list in bytes.
63 * @csbcpb: Logical real address of the 4k naturally-aligned storage block
64 * containing the CSB & optional FC field specific CPB
65 * @timeout: # of milliseconds to retry h_call, 0 for no timeout.
66 * @hcall_err: pointer to return the h_call return value, else NULL
67 */
68struct vio_pfo_op {
69 u64 flags;
70 s64 in;
71 s64 inlen;
72 s64 out;
73 s64 outlen;
74 u64 csbcpb;
75 void *done;
76 unsigned long handle;
77 unsigned int timeout;
78 long hcall_err;
79};
80
81/* End PFO specific data */
82
83enum vio_dev_family {
84 VDEVICE, /* The OF node is a child of /vdevice */
85 PFO, /* The OF node is a child of /ibm,platform-facilities */
86};
87
88/**
89 * vio_dev - This structure is used to describe virtual I/O devices.
90 *
91 * @desired: set from return of driver's get_desired_dma() function
92 * @entitled: bytes of IO data that has been reserved for this device.
93 * @allocated: bytes of IO data currently in use by the device.
94 * @allocs_failed: number of DMA failures due to insufficient entitlement.
95 */
96struct vio_dev {
97 const char *name;
98 const char *type;
99 uint32_t unit_address;
100 uint32_t resource_id;
101 unsigned int irq;
102 struct {
103 size_t desired;
104 size_t entitled;
105 size_t allocated;
106 atomic_t allocs_failed;
107 } cmo;
108 enum vio_dev_family family;
109 struct device dev;
110};
111
112struct vio_driver {
113 const char *name;
114 const struct vio_device_id *id_table;
115 int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
116 void (*remove)(struct vio_dev *dev);
117 void (*shutdown)(struct vio_dev *dev);
118 /* A driver must have a get_desired_dma() function to
119 * be loaded in a CMO environment if it uses DMA.
120 */
121 unsigned long (*get_desired_dma)(struct vio_dev *dev);
122 const struct dev_pm_ops *pm;
123 struct device_driver driver;
124};
125
126extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
127 const char *mod_name);
128/*
129 * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
130 */
131#define vio_register_driver(driver) \
132 __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
133extern void vio_unregister_driver(struct vio_driver *drv);
134
135extern int vio_cmo_entitlement_update(size_t);
136extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired);
137
138extern void vio_unregister_device(struct vio_dev *dev);
139
140extern int vio_h_cop_sync(struct vio_dev *vdev, struct vio_pfo_op *op);
141
142struct device_node;
143
144extern struct vio_dev *vio_register_device_node(
145 struct device_node *node_vdev);
146extern const void *vio_get_attribute(struct vio_dev *vdev, char *which,
147 int *length);
148#ifdef CONFIG_PPC_PSERIES
149extern struct vio_dev *vio_find_node(struct device_node *vnode);
150extern int vio_enable_interrupts(struct vio_dev *dev);
151extern int vio_disable_interrupts(struct vio_dev *dev);
152#else
153static inline int vio_enable_interrupts(struct vio_dev *dev)
154{
155 return 0;
156}
157#endif
158
159static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
160{
161 return container_of(drv, struct vio_driver, driver);
162}
163
164#define to_vio_dev(__dev) container_of_const(__dev, struct vio_dev, dev)
165
166#endif /* __KERNEL__ */
167#endif /* _ASM_POWERPC_VIO_H */
1/*
2 * IBM PowerPC Virtual I/O Infrastructure Support.
3 *
4 * Copyright (c) 2003 IBM Corp.
5 * Dave Engebretsen engebret@us.ibm.com
6 * Santiago Leon santil@us.ibm.com
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
14#ifndef _ASM_POWERPC_VIO_H
15#define _ASM_POWERPC_VIO_H
16#ifdef __KERNEL__
17
18#include <linux/init.h>
19#include <linux/errno.h>
20#include <linux/device.h>
21#include <linux/dma-mapping.h>
22#include <linux/mod_devicetable.h>
23
24#include <asm/hvcall.h>
25#include <asm/scatterlist.h>
26
27/*
28 * Architecture-specific constants for drivers to
29 * extract attributes of the device using vio_get_attribute()
30 */
31#define VETH_MAC_ADDR "local-mac-address"
32#define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters"
33
34/* End architecture-specific constants */
35
36#define h_vio_signal(ua, mode) \
37 plpar_hcall_norets(H_VIO_SIGNAL, ua, mode)
38
39#define VIO_IRQ_DISABLE 0UL
40#define VIO_IRQ_ENABLE 1UL
41
42/*
43 * VIO CMO minimum entitlement for all devices and spare entitlement
44 */
45#define VIO_CMO_MIN_ENT 1562624
46
47struct iommu_table;
48
49/**
50 * vio_dev - This structure is used to describe virtual I/O devices.
51 *
52 * @desired: set from return of driver's get_desired_dma() function
53 * @entitled: bytes of IO data that has been reserved for this device.
54 * @allocated: bytes of IO data currently in use by the device.
55 * @allocs_failed: number of DMA failures due to insufficient entitlement.
56 */
57struct vio_dev {
58 const char *name;
59 const char *type;
60 uint32_t unit_address;
61 unsigned int irq;
62 struct {
63 size_t desired;
64 size_t entitled;
65 size_t allocated;
66 atomic_t allocs_failed;
67 } cmo;
68 struct device dev;
69};
70
71struct vio_driver {
72 const struct vio_device_id *id_table;
73 int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
74 int (*remove)(struct vio_dev *dev);
75 /* A driver must have a get_desired_dma() function to
76 * be loaded in a CMO environment if it uses DMA.
77 */
78 unsigned long (*get_desired_dma)(struct vio_dev *dev);
79 struct device_driver driver;
80};
81
82extern int vio_register_driver(struct vio_driver *drv);
83extern void vio_unregister_driver(struct vio_driver *drv);
84
85extern int vio_cmo_entitlement_update(size_t);
86extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired);
87
88extern void __devinit vio_unregister_device(struct vio_dev *dev);
89
90struct device_node;
91
92extern struct vio_dev *vio_register_device_node(
93 struct device_node *node_vdev);
94extern const void *vio_get_attribute(struct vio_dev *vdev, char *which,
95 int *length);
96#ifdef CONFIG_PPC_PSERIES
97extern struct vio_dev *vio_find_node(struct device_node *vnode);
98extern int vio_enable_interrupts(struct vio_dev *dev);
99extern int vio_disable_interrupts(struct vio_dev *dev);
100#else
101static inline int vio_enable_interrupts(struct vio_dev *dev)
102{
103 return 0;
104}
105#endif
106
107static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
108{
109 return container_of(drv, struct vio_driver, driver);
110}
111
112static inline struct vio_dev *to_vio_dev(struct device *dev)
113{
114 return container_of(dev, struct vio_dev, dev);
115}
116
117#endif /* __KERNEL__ */
118#endif /* _ASM_POWERPC_VIO_H */