staging:iio:accel:adis16204 move to irqchip based trigger handling.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / mei / mei_dev.h
blob6f3ec068ed698fe0a0c7ef405b4d4a2b977ccc13
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 "mei.h"
22 #include "hw.h"
25 * MEI Char Driver Minors
27 #define MEI_MINORS_BASE 1
28 #define MEI_MINORS_COUNT 1
29 #define MEI_MINOR_NUMBER 1
32 * watch dog definition
34 #define MEI_WATCHDOG_DATA_SIZE 16
35 #define MEI_START_WD_DATA_SIZE 20
36 #define MEI_WD_PARAMS_SIZE 4
37 #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
40 * AMTHI Client UUID
42 extern const uuid_le mei_amthi_guid;
45 * Watchdog Client UUID
47 extern const uuid_le mei_wd_guid;
50 * Watchdog independence state message
52 extern const u8 mei_wd_state_independence_msg[3][4];
55 * Number of File descriptors/handles
56 * that can be opened to the driver.
58 * Limit to 253: 255 Total Clients
59 * minus internal client for AMTHI
60 * minus internal client for Watchdog
62 #define MEI_MAX_OPEN_HANDLE_COUNT 253
65 * Number of queue lists used by this driver
67 #define MEI_IO_LISTS_NUMBER 7
70 * Number of Maximum MEI Clients
72 #define MEI_CLIENTS_MAX 255
74 /* File state */
75 enum file_state {
76 MEI_FILE_INITIALIZING = 0,
77 MEI_FILE_CONNECTING,
78 MEI_FILE_CONNECTED,
79 MEI_FILE_DISCONNECTING,
80 MEI_FILE_DISCONNECTED
83 /* MEI device states */
84 enum mei_states {
85 MEI_INITIALIZING = 0,
86 MEI_INIT_CLIENTS,
87 MEI_ENABLED,
88 MEI_RESETING,
89 MEI_DISABLED,
90 MEI_RECOVERING_FROM_RESET,
91 MEI_POWER_DOWN,
92 MEI_POWER_UP
95 /* init clients states*/
96 enum mei_init_clients_states {
97 MEI_START_MESSAGE = 0,
98 MEI_ENUM_CLIENTS_MESSAGE,
99 MEI_CLIENT_PROPERTIES_MESSAGE
102 enum iamthif_states {
103 MEI_IAMTHIF_IDLE,
104 MEI_IAMTHIF_WRITING,
105 MEI_IAMTHIF_FLOW_CONTROL,
106 MEI_IAMTHIF_READING,
107 MEI_IAMTHIF_READ_COMPLETE
110 enum mei_file_transaction_states {
111 MEI_IDLE,
112 MEI_WRITING,
113 MEI_WRITE_COMPLETE,
114 MEI_FLOW_CONTROL,
115 MEI_READING,
116 MEI_READ_COMPLETE
119 /* MEI CB */
120 enum mei_cb_major_types {
121 MEI_READ = 0,
122 MEI_WRITE,
123 MEI_IOCTL,
124 MEI_OPEN,
125 MEI_CLOSE
129 * Intel MEI message data struct
131 struct mei_message_data {
132 u32 size;
133 char *data;
134 } __packed;
137 struct mei_cl_cb {
138 struct list_head cb_list;
139 enum mei_cb_major_types major_file_operations;
140 void *file_private;
141 struct mei_message_data request_buffer;
142 struct mei_message_data response_buffer;
143 unsigned long information;
144 unsigned long read_time;
145 struct file *file_object;
148 /* MEI client instance carried as file->pirvate_data*/
149 struct mei_cl {
150 struct list_head link;
151 struct mei_device *dev;
152 enum file_state state;
153 wait_queue_head_t tx_wait;
154 wait_queue_head_t rx_wait;
155 wait_queue_head_t wait;
156 int read_pending;
157 int status;
158 /* ID of client connected */
159 u8 host_client_id;
160 u8 me_client_id;
161 u8 mei_flow_ctrl_creds;
162 u8 timer_count;
163 enum mei_file_transaction_states reading_state;
164 enum mei_file_transaction_states writing_state;
165 int sm_state;
166 struct mei_cl_cb *read_cb;
169 struct mei_io_list {
170 struct mei_cl_cb mei_cb;
171 int status;
172 struct mei_device *device_extension;
175 /* MEI private device struct */
176 struct mei_device {
177 struct pci_dev *pdev; /* pointer to pci device struct */
179 * lists of queues
181 /* array of pointers to aio lists */
182 struct mei_io_list *io_list_array[MEI_IO_LISTS_NUMBER];
183 struct mei_io_list read_list; /* driver read queue */
184 struct mei_io_list write_list; /* driver write queue */
185 struct mei_io_list write_waiting_list; /* write waiting queue */
186 struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
187 struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
188 struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
190 /* driver managed amthi list for reading completed amthi cmd data */
191 struct mei_io_list amthi_read_complete_list;
193 * list of files
195 struct list_head file_list;
197 * memory of device
199 unsigned int mem_base;
200 unsigned int mem_length;
201 void __iomem *mem_addr;
203 * lock for the device
205 struct mutex device_lock; /* device lock */
206 int recvd_msg;
207 struct delayed_work wd_work; /* watch dog deleye work */
209 * hw states of host and fw(ME)
211 u32 host_hw_state;
212 u32 me_hw_state;
214 * waiting queue for receive message from FW
216 wait_queue_head_t wait_recvd_msg;
217 wait_queue_head_t wait_stop_wd;
220 * mei device states
222 enum mei_states mei_state;
223 enum mei_init_clients_states init_clients_state;
224 u16 init_clients_timer;
225 int stop;
227 u32 extra_write_index;
228 u32 rd_msg_buf[128]; /* used for control messages */
229 u32 wr_msg_buf[128]; /* used for control messages */
230 u32 ext_msg_buf[8]; /* for control responses */
231 u32 rd_msg_hdr;
233 struct hbm_version version;
235 int mei_host_buffer_is_empty;
236 struct mei_cl wd_cl;
237 struct mei_me_client *me_clients; /* Note: memory has to be allocated */
238 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
239 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
240 u8 num_mei_me_clients;
241 u8 me_client_presentation_num;
242 u8 me_client_index;
244 int wd_pending;
245 int wd_stopped;
246 u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
247 unsigned char wd_data[MEI_START_WD_DATA_SIZE];
250 u16 wd_due_counter;
251 bool wd_bypass; /* if false, don't refresh watchdog ME client */
253 struct file *iamthif_file_object;
254 struct mei_cl iamthif_cl;
255 int iamthif_ioctl;
256 int iamthif_canceled;
257 int iamthif_mtu;
258 unsigned long iamthif_timer;
259 u32 iamthif_stall_timer;
260 unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
261 u32 iamthif_msg_buf_size;
262 u32 iamthif_msg_buf_index;
263 int iamthif_flow_control_pending;
264 enum iamthif_states iamthif_state;
265 struct mei_cl_cb *iamthif_current_cb;
266 u8 write_hang;
267 int need_reset;
268 long open_handle_count;
274 * mei init function prototypes
276 struct mei_device *init_mei_device(struct pci_dev *pdev);
277 void mei_reset(struct mei_device *dev, int interrupts);
278 int mei_hw_init(struct mei_device *dev);
279 int mei_task_initialize_clients(void *data);
280 int mei_initialize_clients(struct mei_device *dev);
281 struct mei_cl *mei_alloc_file_private(struct mei_device *dev);
282 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
283 void mei_initialize_list(struct mei_io_list *list,
284 struct mei_device *dev);
285 void mei_flush_list(struct mei_io_list *list, struct mei_cl *cl);
286 void mei_flush_queues(struct mei_device *dev, struct mei_cl *cl);
287 void mei_remove_client_from_file_list(struct mei_device *dev,
288 u8 host_client_id);
289 void host_init_iamthif(struct mei_device *dev);
290 void mei_init_file_private(struct mei_cl *priv, struct mei_device *dev);
291 void allocate_me_clients_storage(struct mei_device *dev);
293 void host_start_message(struct mei_device *dev);
294 void host_enum_clients_message(struct mei_device *dev);
295 void host_client_properties(struct mei_device *dev);
297 u8 mei_find_me_client_update_filext(struct mei_device *dev,
298 struct mei_cl *priv,
299 const uuid_le *cguid, u8 client_id);
302 * interrupt functions prototype
304 irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
305 irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
306 void mei_wd_timer(struct work_struct *work);
309 * input output function prototype
311 int mei_ioctl_connect_client(struct file *file,
312 struct mei_connect_client_data *data);
314 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
316 int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
318 int amthi_read(struct mei_device *dev, struct file *file,
319 char __user *ubuf, size_t length, loff_t *offset);
321 struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
322 struct file *file);
324 void run_next_iamthif_cmd(struct mei_device *dev);
326 void mei_free_cb_private(struct mei_cl_cb *priv_cb);
328 int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
331 * Register Access Function
335 * mei_reg_read - Reads 32bit data from the mei device
337 * @dev: the device structure
338 * @offset: offset from which to read the data
340 * returns the byte read.
342 static inline u32 mei_reg_read(struct mei_device *dev,
343 unsigned long offset)
345 return ioread32(dev->mem_addr + offset);
349 * mei_reg_write - Writes 32bit data to the mei device
351 * @dev: the device structure
352 * @offset: offset from which to write the data
353 * @value: the byte to write
355 static inline void mei_reg_write(struct mei_device *dev,
356 unsigned long offset, u32 value)
358 iowrite32(value, dev->mem_addr + offset);
362 * mei_hcsr_read - Reads 32bit data from the host CSR
364 * @dev: the device structure
366 * returns the byte read.
368 static inline u32 mei_hcsr_read(struct mei_device *dev)
370 return mei_reg_read(dev, H_CSR);
374 * mei_mecsr_read - Reads 32bit data from the ME CSR
376 * @dev: the device structure
378 * returns ME_CSR_HA register value (u32)
380 static inline u32 mei_mecsr_read(struct mei_device *dev)
382 return mei_reg_read(dev, ME_CSR_HA);
386 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
388 * @dev: the device structure
390 * returns ME_CB_RW register value (u32)
392 static inline u32 mei_mecbrw_read(struct mei_device *dev)
394 return mei_reg_read(dev, ME_CB_RW);
399 * mei interface function prototypes
401 void mei_hcsr_set(struct mei_device *dev);
402 void mei_csr_clear_his(struct mei_device *dev);
404 void mei_enable_interrupts(struct mei_device *dev);
405 void mei_disable_interrupts(struct mei_device *dev);
408 * mei_fe_same_id - tells if file private data have same id
410 * @fe1: private data of 1. file object
411 * @fe2: private data of 2. file object
413 * returns !=0 - if ids are the same, 0 - if differ.
415 static inline int mei_fe_same_id(const struct mei_cl *fe1,
416 const struct mei_cl *fe2)
418 return ((fe1->host_client_id == fe2->host_client_id) &&
419 (fe1->me_client_id == fe2->me_client_id));
422 #endif