]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/fsl-mc/include/mc.h
Merge tag 'v4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux...
[karo-tx-linux.git] / drivers / staging / fsl-mc / include / mc.h
1 /*
2  * Freescale Management Complex (MC) bus public interface
3  *
4  * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
5  * Author: German Rivera <German.Rivera@freescale.com>
6  *
7  * This file is licensed under the terms of the GNU General Public
8  * License version 2. This program is licensed "as is" without any
9  * warranty of any kind, whether express or implied.
10  */
11 #ifndef _FSL_MC_H_
12 #define _FSL_MC_H_
13
14 #include <linux/device.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/interrupt.h>
17 #include "../include/dprc.h"
18
19 #define FSL_MC_VENDOR_FREESCALE 0x1957
20
21 struct fsl_mc_device;
22 struct fsl_mc_io;
23
24 /**
25  * struct fsl_mc_driver - MC object device driver object
26  * @driver: Generic device driver
27  * @match_id_table: table of supported device matching Ids
28  * @probe: Function called when a device is added
29  * @remove: Function called when a device is removed
30  * @shutdown: Function called at shutdown time to quiesce the device
31  * @suspend: Function called when a device is stopped
32  * @resume: Function called when a device is resumed
33  *
34  * Generic DPAA device driver object for device drivers that are registered
35  * with a DPRC bus. This structure is to be embedded in each device-specific
36  * driver structure.
37  */
38 struct fsl_mc_driver {
39         struct device_driver driver;
40         const struct fsl_mc_device_id *match_id_table;
41         int (*probe)(struct fsl_mc_device *dev);
42         int (*remove)(struct fsl_mc_device *dev);
43         void (*shutdown)(struct fsl_mc_device *dev);
44         int (*suspend)(struct fsl_mc_device *dev, pm_message_t state);
45         int (*resume)(struct fsl_mc_device *dev);
46 };
47
48 #define to_fsl_mc_driver(_drv) \
49         container_of(_drv, struct fsl_mc_driver, driver)
50
51 /**
52  * enum fsl_mc_pool_type - Types of allocatable MC bus resources
53  *
54  * Entries in these enum are used as indices in the array of resource
55  * pools of an fsl_mc_bus object.
56  */
57 enum fsl_mc_pool_type {
58         FSL_MC_POOL_DPMCP = 0x0,    /* corresponds to "dpmcp" in the MC */
59         FSL_MC_POOL_DPBP,           /* corresponds to "dpbp" in the MC */
60         FSL_MC_POOL_DPCON,          /* corresponds to "dpcon" in the MC */
61         FSL_MC_POOL_IRQ,
62
63         /*
64          * NOTE: New resource pool types must be added before this entry
65          */
66         FSL_MC_NUM_POOL_TYPES
67 };
68
69 /**
70  * struct fsl_mc_resource - MC generic resource
71  * @type: type of resource
72  * @id: unique MC resource Id within the resources of the same type
73  * @data: pointer to resource-specific data if the resource is currently
74  * allocated, or NULL if the resource is not currently allocated.
75  * @parent_pool: pointer to the parent resource pool from which this
76  * resource is allocated from.
77  * @node: Node in the free list of the corresponding resource pool
78  *
79  * NOTE: This structure is to be embedded as a field of specific
80  * MC resource structures.
81  */
82 struct fsl_mc_resource {
83         enum fsl_mc_pool_type type;
84         s32 id;
85         void *data;
86         struct fsl_mc_resource_pool *parent_pool;
87         struct list_head node;
88 };
89
90 /**
91  * struct fsl_mc_device_irq - MC object device message-based interrupt
92  * @msi_desc: pointer to MSI descriptor allocated by fsl_mc_msi_alloc_descs()
93  * @mc_dev: MC object device that owns this interrupt
94  * @dev_irq_index: device-relative IRQ index
95  * @resource: MC generic resource associated with the interrupt
96  */
97 struct fsl_mc_device_irq {
98         struct msi_desc *msi_desc;
99         struct fsl_mc_device *mc_dev;
100         u8 dev_irq_index;
101         struct fsl_mc_resource resource;
102 };
103
104 #define to_fsl_mc_irq(_mc_resource) \
105         container_of(_mc_resource, struct fsl_mc_device_irq, resource)
106
107 /**
108  * Bit masks for a MC object device (struct fsl_mc_device) flags
109  */
110 #define FSL_MC_IS_DPRC  0x0001
111
112 /**
113  * struct fsl_mc_device - MC object device object
114  * @dev: Linux driver model device object
115  * @dma_mask: Default DMA mask
116  * @flags: MC object device flags
117  * @icid: Isolation context ID for the device
118  * @mc_handle: MC handle for the corresponding MC object opened
119  * @mc_io: Pointer to MC IO object assigned to this device or
120  * NULL if none.
121  * @obj_desc: MC description of the DPAA device
122  * @regions: pointer to array of MMIO region entries
123  * @irqs: pointer to array of pointers to interrupts allocated to this device
124  * @resource: generic resource associated with this MC object device, if any.
125  *
126  * Generic device object for MC object devices that are "attached" to a
127  * MC bus.
128  *
129  * NOTES:
130  * - For a non-DPRC object its icid is the same as its parent DPRC's icid.
131  * - The SMMU notifier callback gets invoked after device_add() has been
132  *   called for an MC object device, but before the device-specific probe
133  *   callback gets called.
134  * - DP_OBJ_DPRC objects are the only MC objects that have built-in MC
135  *   portals. For all other MC objects, their device drivers are responsible for
136  *   allocating MC portals for them by calling fsl_mc_portal_allocate().
137  * - Some types of MC objects (e.g., DP_OBJ_DPBP, DP_OBJ_DPCON) are
138  *   treated as resources that can be allocated/deallocated from the
139  *   corresponding resource pool in the object's parent DPRC, using the
140  *   fsl_mc_object_allocate()/fsl_mc_object_free() functions. These MC objects
141  *   are known as "allocatable" objects. For them, the corresponding
142  *   fsl_mc_device's 'resource' points to the associated resource object.
143  *   For MC objects that are not allocatable (e.g., DP_OBJ_DPRC, DP_OBJ_DPNI),
144  *   'resource' is NULL.
145  */
146 struct fsl_mc_device {
147         struct device dev;
148         u64 dma_mask;
149         u16 flags;
150         u16 icid;
151         u16 mc_handle;
152         struct fsl_mc_io *mc_io;
153         struct dprc_obj_desc obj_desc;
154         struct resource *regions;
155         struct fsl_mc_device_irq **irqs;
156         struct fsl_mc_resource *resource;
157 };
158
159 #define to_fsl_mc_device(_dev) \
160         container_of(_dev, struct fsl_mc_device, dev)
161
162 /*
163  * module_fsl_mc_driver() - Helper macro for drivers that don't do
164  * anything special in module init/exit.  This eliminates a lot of
165  * boilerplate.  Each module may only use this macro once, and
166  * calling it replaces module_init() and module_exit()
167  */
168 #define module_fsl_mc_driver(__fsl_mc_driver) \
169         module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
170                       fsl_mc_driver_unregister)
171
172 /*
173  * Macro to avoid include chaining to get THIS_MODULE
174  */
175 #define fsl_mc_driver_register(drv) \
176         __fsl_mc_driver_register(drv, THIS_MODULE)
177
178 int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
179                                           struct module *owner);
180
181 void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
182
183 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
184                                         u16 mc_io_flags,
185                                         struct fsl_mc_io **new_mc_io);
186
187 void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
188
189 int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
190
191 int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
192                                         enum fsl_mc_pool_type pool_type,
193                                         struct fsl_mc_device **new_mc_adev);
194
195 void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
196
197 int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
198
199 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
200
201 #endif /* _FSL_MC_H_ */