blob: 16551d5eac36a70a1fefd1a0ee4d997df18d15c1 [file] [log] [blame]
Alan Tull6a8c3be2015-10-07 16:36:28 +01001/*
2 * FPGA Framework
3 *
4 * Copyright (C) 2013-2015 Altera Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include <linux/mutex.h>
19#include <linux/platform_device.h>
20
21#ifndef _LINUX_FPGA_MGR_H
22#define _LINUX_FPGA_MGR_H
23
24struct fpga_manager;
25
26/**
27 * enum fpga_mgr_states - fpga framework states
28 * @FPGA_MGR_STATE_UNKNOWN: can't determine state
29 * @FPGA_MGR_STATE_POWER_OFF: FPGA power is off
30 * @FPGA_MGR_STATE_POWER_UP: FPGA reports power is up
31 * @FPGA_MGR_STATE_RESET: FPGA in reset state
32 * @FPGA_MGR_STATE_FIRMWARE_REQ: firmware request in progress
33 * @FPGA_MGR_STATE_FIRMWARE_REQ_ERR: firmware request failed
34 * @FPGA_MGR_STATE_WRITE_INIT: preparing FPGA for programming
35 * @FPGA_MGR_STATE_WRITE_INIT_ERR: Error during WRITE_INIT stage
36 * @FPGA_MGR_STATE_WRITE: writing image to FPGA
37 * @FPGA_MGR_STATE_WRITE_ERR: Error while writing FPGA
38 * @FPGA_MGR_STATE_WRITE_COMPLETE: Doing post programming steps
39 * @FPGA_MGR_STATE_WRITE_COMPLETE_ERR: Error during WRITE_COMPLETE
40 * @FPGA_MGR_STATE_OPERATING: FPGA is programmed and operating
41 */
42enum fpga_mgr_states {
43 /* default FPGA states */
44 FPGA_MGR_STATE_UNKNOWN,
45 FPGA_MGR_STATE_POWER_OFF,
46 FPGA_MGR_STATE_POWER_UP,
47 FPGA_MGR_STATE_RESET,
48
49 /* getting an image for loading */
50 FPGA_MGR_STATE_FIRMWARE_REQ,
51 FPGA_MGR_STATE_FIRMWARE_REQ_ERR,
52
53 /* write sequence: init, write, complete */
54 FPGA_MGR_STATE_WRITE_INIT,
55 FPGA_MGR_STATE_WRITE_INIT_ERR,
56 FPGA_MGR_STATE_WRITE,
57 FPGA_MGR_STATE_WRITE_ERR,
58 FPGA_MGR_STATE_WRITE_COMPLETE,
59 FPGA_MGR_STATE_WRITE_COMPLETE_ERR,
60
61 /* fpga is programmed and operating */
62 FPGA_MGR_STATE_OPERATING,
63};
64
65/*
66 * FPGA Manager flags
67 * FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported
Alan Tull0fa20cd2016-11-01 14:14:29 -050068 * FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting
Alan Tull6a8c3be2015-10-07 16:36:28 +010069 */
70#define FPGA_MGR_PARTIAL_RECONFIG BIT(0)
Alan Tull0fa20cd2016-11-01 14:14:29 -050071#define FPGA_MGR_EXTERNAL_CONFIG BIT(1)
Alan Tull6a8c3be2015-10-07 16:36:28 +010072
73/**
Alan Tull1df28652016-11-01 14:14:26 -050074 * struct fpga_image_info - information specific to a FPGA image
75 * @flags: boolean flags as defined above
76 * @enable_timeout_us: maximum time to enable traffic through bridge (uSec)
77 * @disable_timeout_us: maximum time to disable traffic through bridge (uSec)
78 */
79struct fpga_image_info {
80 u32 flags;
81 u32 enable_timeout_us;
82 u32 disable_timeout_us;
83};
84
85/**
Alan Tull6a8c3be2015-10-07 16:36:28 +010086 * struct fpga_manager_ops - ops for low level fpga manager drivers
Jason Gunthorpe1d7f1582016-11-22 18:22:09 +000087 * @initial_header_size: Maximum number of bytes that should be passed into write_init
Alan Tull6a8c3be2015-10-07 16:36:28 +010088 * @state: returns an enum value of the FPGA's state
89 * @write_init: prepare the FPGA to receive confuration data
90 * @write: write count bytes of configuration data to the FPGA
91 * @write_complete: set FPGA to operating state after writing is done
92 * @fpga_remove: optional: Set FPGA into a specific state during driver remove
93 *
94 * fpga_manager_ops are the low level functions implemented by a specific
95 * fpga manager driver. The optional ones are tested for NULL before being
96 * called, so leaving them out is fine.
97 */
98struct fpga_manager_ops {
Jason Gunthorpe1d7f1582016-11-22 18:22:09 +000099 size_t initial_header_size;
Alan Tull6a8c3be2015-10-07 16:36:28 +0100100 enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
Alan Tull1df28652016-11-01 14:14:26 -0500101 int (*write_init)(struct fpga_manager *mgr,
102 struct fpga_image_info *info,
Alan Tull6a8c3be2015-10-07 16:36:28 +0100103 const char *buf, size_t count);
104 int (*write)(struct fpga_manager *mgr, const char *buf, size_t count);
Alan Tull1df28652016-11-01 14:14:26 -0500105 int (*write_complete)(struct fpga_manager *mgr,
106 struct fpga_image_info *info);
Alan Tull6a8c3be2015-10-07 16:36:28 +0100107 void (*fpga_remove)(struct fpga_manager *mgr);
108};
109
110/**
111 * struct fpga_manager - fpga manager structure
112 * @name: name of low level fpga manager
113 * @dev: fpga manager device
114 * @ref_mutex: only allows one reference to fpga manager
115 * @state: state of fpga manager
116 * @mops: pointer to struct of fpga manager ops
117 * @priv: low level driver private date
118 */
119struct fpga_manager {
120 const char *name;
121 struct device dev;
122 struct mutex ref_mutex;
123 enum fpga_mgr_states state;
124 const struct fpga_manager_ops *mops;
125 void *priv;
126};
127
128#define to_fpga_manager(d) container_of(d, struct fpga_manager, dev)
129
Alan Tull1df28652016-11-01 14:14:26 -0500130int fpga_mgr_buf_load(struct fpga_manager *mgr, struct fpga_image_info *info,
Alan Tull6a8c3be2015-10-07 16:36:28 +0100131 const char *buf, size_t count);
132
Alan Tull1df28652016-11-01 14:14:26 -0500133int fpga_mgr_firmware_load(struct fpga_manager *mgr,
134 struct fpga_image_info *info,
Alan Tull6a8c3be2015-10-07 16:36:28 +0100135 const char *image_name);
136
137struct fpga_manager *of_fpga_mgr_get(struct device_node *node);
138
Alan Tull9dce0282016-11-01 14:14:23 -0500139struct fpga_manager *fpga_mgr_get(struct device *dev);
140
Alan Tull6a8c3be2015-10-07 16:36:28 +0100141void fpga_mgr_put(struct fpga_manager *mgr);
142
143int fpga_mgr_register(struct device *dev, const char *name,
144 const struct fpga_manager_ops *mops, void *priv);
145
146void fpga_mgr_unregister(struct device *dev);
147
148#endif /*_LINUX_FPGA_MGR_H */