Revert "Staging: comedi: integer overflow in do_insnlist_ioctl()"
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / mei / mei_dev.h
blobaf4b1af9eeac93e833e3a41585e2654d215e3b94
1 /*
3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2011, Intel Corporation.
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.
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.
17 #ifndef _MEI_DEV_H_
18 #define _MEI_DEV_H_
20 #include <linux/types.h>
21 #include <linux/watchdog.h>
22 #include "mei.h"
23 #include "hw.h"
26 * MEI Char Driver Minors
28 #define MEI_MINORS_BASE 1
29 #define MEI_MINORS_COUNT 1
30 #define MEI_MINOR_NUMBER 1
33 * watch dog definition
35 #define MEI_WATCHDOG_DATA_SIZE 16
36 #define MEI_START_WD_DATA_SIZE 20
37 #define MEI_WD_PARAMS_SIZE 4
38 #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
41 * MEI PCI Device object
43 extern struct pci_dev *mei_device;
46 * AMT Watchdog Device
48 #define INTEL_AMT_WATCHDOG_ID "INTCAMT"
49 extern struct watchdog_device amt_wd_dev;
52 * AMTHI Client UUID
54 extern const uuid_le mei_amthi_guid;
57 * Watchdog Client UUID
59 extern const uuid_le mei_wd_guid;
62 * Watchdog independence state message
64 extern const u8 mei_wd_state_independence_msg[3][4];
67 * Number of File descriptors/handles
68 * that can be opened to the driver.
70 * Limit to 253: 255 Total Clients
71 * minus internal client for AMTHI
72 * minus internal client for Watchdog
74 #define MEI_MAX_OPEN_HANDLE_COUNT 253
77 * Number of Maximum MEI Clients
79 #define MEI_CLIENTS_MAX 255
81 /* File state */
82 enum file_state {
83 MEI_FILE_INITIALIZING = 0,
84 MEI_FILE_CONNECTING,
85 MEI_FILE_CONNECTED,
86 MEI_FILE_DISCONNECTING,
87 MEI_FILE_DISCONNECTED
90 /* MEI device states */
91 enum mei_states {
92 MEI_INITIALIZING = 0,
93 MEI_INIT_CLIENTS,
94 MEI_ENABLED,
95 MEI_RESETING,
96 MEI_DISABLED,
97 MEI_RECOVERING_FROM_RESET,
98 MEI_POWER_DOWN,
99 MEI_POWER_UP
102 /* init clients states*/
103 enum mei_init_clients_states {
104 MEI_START_MESSAGE = 0,
105 MEI_ENUM_CLIENTS_MESSAGE,
106 MEI_CLIENT_PROPERTIES_MESSAGE
109 enum iamthif_states {
110 MEI_IAMTHIF_IDLE,
111 MEI_IAMTHIF_WRITING,
112 MEI_IAMTHIF_FLOW_CONTROL,
113 MEI_IAMTHIF_READING,
114 MEI_IAMTHIF_READ_COMPLETE
117 enum mei_file_transaction_states {
118 MEI_IDLE,
119 MEI_WRITING,
120 MEI_WRITE_COMPLETE,
121 MEI_FLOW_CONTROL,
122 MEI_READING,
123 MEI_READ_COMPLETE
126 /* MEI CB */
127 enum mei_cb_major_types {
128 MEI_READ = 0,
129 MEI_WRITE,
130 MEI_IOCTL,
131 MEI_OPEN,
132 MEI_CLOSE
136 * Intel MEI message data struct
138 struct mei_message_data {
139 u32 size;
140 char *data;
141 } __packed;
144 struct mei_cl_cb {
145 struct list_head cb_list;
146 enum mei_cb_major_types major_file_operations;
147 void *file_private;
148 struct mei_message_data request_buffer;
149 struct mei_message_data response_buffer;
150 unsigned long information;
151 unsigned long read_time;
152 struct file *file_object;
155 /* MEI client instance carried as file->pirvate_data*/
156 struct mei_cl {
157 struct list_head link;
158 struct mei_device *dev;
159 enum file_state state;
160 wait_queue_head_t tx_wait;
161 wait_queue_head_t rx_wait;
162 wait_queue_head_t wait;
163 int read_pending;
164 int status;
165 /* ID of client connected */
166 u8 host_client_id;
167 u8 me_client_id;
168 u8 mei_flow_ctrl_creds;
169 u8 timer_count;
170 enum mei_file_transaction_states reading_state;
171 enum mei_file_transaction_states writing_state;
172 int sm_state;
173 struct mei_cl_cb *read_cb;
176 struct mei_io_list {
177 struct mei_cl_cb mei_cb;
178 int status;
181 /* MEI private device struct */
182 struct mei_device {
183 struct pci_dev *pdev; /* pointer to pci device struct */
185 * lists of queues
187 /* array of pointers to aio lists */
188 struct mei_io_list read_list; /* driver read queue */
189 struct mei_io_list write_list; /* driver write queue */
190 struct mei_io_list write_waiting_list; /* write waiting queue */
191 struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
192 struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
193 struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
195 /* driver managed amthi list for reading completed amthi cmd data */
196 struct mei_io_list amthi_read_complete_list;
198 * list of files
200 struct list_head file_list;
201 long open_handle_count;
203 * memory of device
205 unsigned int mem_base;
206 unsigned int mem_length;
207 void __iomem *mem_addr;
209 * lock for the device
211 struct mutex device_lock; /* device lock */
212 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
213 bool recvd_msg;
215 * hw states of host and fw(ME)
217 u32 host_hw_state;
218 u32 me_hw_state;
220 * waiting queue for receive message from FW
222 wait_queue_head_t wait_recvd_msg;
223 wait_queue_head_t wait_stop_wd;
226 * mei device states
228 enum mei_states mei_state;
229 enum mei_init_clients_states init_clients_state;
230 u16 init_clients_timer;
231 bool stop;
232 bool need_reset;
234 u32 extra_write_index;
235 u32 rd_msg_buf[128]; /* used for control messages */
236 u32 wr_msg_buf[128]; /* used for control messages */
237 u32 ext_msg_buf[8]; /* for control responses */
238 u32 rd_msg_hdr;
240 struct hbm_version version;
242 struct mei_me_client *me_clients; /* Note: memory has to be allocated */
243 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
244 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
245 u8 me_clients_num;
246 u8 me_client_presentation_num;
247 u8 me_client_index;
248 bool mei_host_buffer_is_empty;
250 struct mei_cl wd_cl;
251 bool wd_pending;
252 bool wd_stopped;
253 bool wd_bypass; /* if false, don't refresh watchdog ME client */
254 u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
255 u16 wd_due_counter;
256 unsigned char wd_data[MEI_START_WD_DATA_SIZE];
260 struct file *iamthif_file_object;
261 struct mei_cl iamthif_cl;
262 struct mei_cl_cb *iamthif_current_cb;
263 int iamthif_mtu;
264 unsigned long iamthif_timer;
265 u32 iamthif_stall_timer;
266 unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
267 u32 iamthif_msg_buf_size;
268 u32 iamthif_msg_buf_index;
269 enum iamthif_states iamthif_state;
270 bool iamthif_flow_control_pending;
271 bool iamthif_ioctl;
272 bool iamthif_canceled;
274 bool wd_interface_reg;
279 * mei init function prototypes
281 struct mei_device *mei_device_init(struct pci_dev *pdev);
282 void mei_reset(struct mei_device *dev, int interrupts);
283 int mei_hw_init(struct mei_device *dev);
284 int mei_task_initialize_clients(void *data);
285 int mei_initialize_clients(struct mei_device *dev);
286 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
287 void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
288 void mei_host_init_iamthif(struct mei_device *dev);
289 void mei_allocate_me_clients_storage(struct mei_device *dev);
292 u8 mei_find_me_client_update_filext(struct mei_device *dev,
293 struct mei_cl *priv,
294 const uuid_le *cguid, u8 client_id);
297 * MEI IO List Functions
299 void mei_io_list_init(struct mei_io_list *list);
300 void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
303 * MEI ME Client Functions
306 struct mei_cl *mei_cl_allocate(struct mei_device *dev);
307 void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
308 int mei_cl_flush_queues(struct mei_cl *cl);
310 * mei_cl_cmp_id - tells if file private data have same id
312 * @fe1: private data of 1. file object
313 * @fe2: private data of 2. file object
315 * returns true - if ids are the same and not NULL
317 static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
318 const struct mei_cl *cl2)
320 return cl1 && cl2 &&
321 (cl1->host_client_id == cl2->host_client_id) &&
322 (cl1->me_client_id == cl2->me_client_id);
328 * MEI Host Client Functions
330 void mei_host_start_message(struct mei_device *dev);
331 void mei_host_enum_clients_message(struct mei_device *dev);
332 int mei_host_client_properties(struct mei_device *dev);
335 * MEI interrupt functions prototype
337 irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
338 irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
339 void mei_timer(struct work_struct *work);
342 * MEI input output function prototype
344 int mei_ioctl_connect_client(struct file *file,
345 struct mei_connect_client_data *data);
347 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
349 int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
351 int amthi_read(struct mei_device *dev, struct file *file,
352 char __user *ubuf, size_t length, loff_t *offset);
354 struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
355 struct file *file);
357 void mei_run_next_iamthif_cmd(struct mei_device *dev);
359 void mei_free_cb_private(struct mei_cl_cb *priv_cb);
361 int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
364 * Register Access Function
368 * mei_reg_read - Reads 32bit data from the mei device
370 * @dev: the device structure
371 * @offset: offset from which to read the data
373 * returns register value (u32)
375 static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset)
377 return ioread32(dev->mem_addr + offset);
381 * mei_reg_write - Writes 32bit data to the mei device
383 * @dev: the device structure
384 * @offset: offset from which to write the data
385 * @value: register value to write (u32)
387 static inline void mei_reg_write(struct mei_device *dev,
388 unsigned long offset, u32 value)
390 iowrite32(value, dev->mem_addr + offset);
394 * mei_hcsr_read - Reads 32bit data from the host CSR
396 * @dev: the device structure
398 * returns the byte read.
400 static inline u32 mei_hcsr_read(struct mei_device *dev)
402 return mei_reg_read(dev, H_CSR);
406 * mei_mecsr_read - Reads 32bit data from the ME CSR
408 * @dev: the device structure
410 * returns ME_CSR_HA register value (u32)
412 static inline u32 mei_mecsr_read(struct mei_device *dev)
414 return mei_reg_read(dev, ME_CSR_HA);
418 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
420 * @dev: the device structure
422 * returns ME_CB_RW register value (u32)
424 static inline u32 mei_mecbrw_read(struct mei_device *dev)
426 return mei_reg_read(dev, ME_CB_RW);
431 * mei interface function prototypes
433 void mei_hcsr_set(struct mei_device *dev);
434 void mei_csr_clear_his(struct mei_device *dev);
436 void mei_enable_interrupts(struct mei_device *dev);
437 void mei_disable_interrupts(struct mei_device *dev);
439 #endif