Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
Tomas Winkler | 733ba91c | 2012-02-09 19:25:53 +0200 | [diff] [blame] | 4 | * Copyright (c) 2003-2012, Intel Corporation. |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | #ifndef _MEI_DEV_H_ |
| 18 | #define _MEI_DEV_H_ |
| 19 | |
| 20 | #include <linux/types.h> |
Oren Weil | 9ce178e | 2011-09-07 09:03:09 +0300 | [diff] [blame] | 21 | #include <linux/watchdog.h> |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 22 | #include <linux/mei.h> |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 23 | #include "hw.h" |
| 24 | |
| 25 | /* |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 26 | * watch dog definition |
| 27 | */ |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame^] | 28 | #define MEI_WD_HDR_SIZE 4 |
| 29 | #define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE |
| 30 | #define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16) |
| 31 | |
| 32 | #define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */ |
| 33 | #define MEI_WD_MIN_TIMEOUT 120 /* seconds */ |
| 34 | #define MEI_WD_MAX_TIMEOUT 65535 /* seconds */ |
| 35 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 36 | #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0) |
| 37 | |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 38 | #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32)) |
| 39 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 40 | /* |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 41 | * MEI PCI Device object |
| 42 | */ |
| 43 | extern struct pci_dev *mei_device; |
| 44 | |
Oren Weil | 9ce178e | 2011-09-07 09:03:09 +0300 | [diff] [blame] | 45 | |
| 46 | /* |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 47 | * AMTHI Client UUID |
| 48 | */ |
| 49 | extern const uuid_le mei_amthi_guid; |
| 50 | |
| 51 | /* |
| 52 | * Watchdog Client UUID |
| 53 | */ |
| 54 | extern const uuid_le mei_wd_guid; |
| 55 | |
| 56 | /* |
| 57 | * Watchdog independence state message |
| 58 | */ |
| 59 | extern const u8 mei_wd_state_independence_msg[3][4]; |
| 60 | |
| 61 | /* |
| 62 | * Number of File descriptors/handles |
| 63 | * that can be opened to the driver. |
| 64 | * |
| 65 | * Limit to 253: 255 Total Clients |
| 66 | * minus internal client for AMTHI |
| 67 | * minus internal client for Watchdog |
| 68 | */ |
| 69 | #define MEI_MAX_OPEN_HANDLE_COUNT 253 |
| 70 | |
| 71 | /* |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 72 | * Number of Maximum MEI Clients |
| 73 | */ |
| 74 | #define MEI_CLIENTS_MAX 255 |
| 75 | |
| 76 | /* File state */ |
| 77 | enum file_state { |
| 78 | MEI_FILE_INITIALIZING = 0, |
| 79 | MEI_FILE_CONNECTING, |
| 80 | MEI_FILE_CONNECTED, |
| 81 | MEI_FILE_DISCONNECTING, |
| 82 | MEI_FILE_DISCONNECTED |
| 83 | }; |
| 84 | |
| 85 | /* MEI device states */ |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 86 | enum mei_dev_state { |
| 87 | MEI_DEV_INITIALIZING = 0, |
| 88 | MEI_DEV_INIT_CLIENTS, |
| 89 | MEI_DEV_ENABLED, |
| 90 | MEI_DEV_RESETING, |
| 91 | MEI_DEV_DISABLED, |
| 92 | MEI_DEV_RECOVERING_FROM_RESET, |
| 93 | MEI_DEV_POWER_DOWN, |
| 94 | MEI_DEV_POWER_UP |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 95 | }; |
| 96 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 97 | const char *mei_dev_state_str(int state); |
| 98 | |
Justin P. Mattock | 5f9092f3 | 2012-03-12 07:18:09 -0700 | [diff] [blame] | 99 | /* init clients states*/ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 100 | enum mei_init_clients_states { |
| 101 | MEI_START_MESSAGE = 0, |
| 102 | MEI_ENUM_CLIENTS_MESSAGE, |
| 103 | MEI_CLIENT_PROPERTIES_MESSAGE |
| 104 | }; |
| 105 | |
| 106 | enum iamthif_states { |
| 107 | MEI_IAMTHIF_IDLE, |
| 108 | MEI_IAMTHIF_WRITING, |
| 109 | MEI_IAMTHIF_FLOW_CONTROL, |
| 110 | MEI_IAMTHIF_READING, |
| 111 | MEI_IAMTHIF_READ_COMPLETE |
| 112 | }; |
| 113 | |
| 114 | enum mei_file_transaction_states { |
| 115 | MEI_IDLE, |
| 116 | MEI_WRITING, |
| 117 | MEI_WRITE_COMPLETE, |
| 118 | MEI_FLOW_CONTROL, |
| 119 | MEI_READING, |
| 120 | MEI_READ_COMPLETE |
| 121 | }; |
| 122 | |
| 123 | /* MEI CB */ |
| 124 | enum mei_cb_major_types { |
| 125 | MEI_READ = 0, |
| 126 | MEI_WRITE, |
| 127 | MEI_IOCTL, |
| 128 | MEI_OPEN, |
| 129 | MEI_CLOSE |
| 130 | }; |
| 131 | |
| 132 | /* |
| 133 | * Intel MEI message data struct |
| 134 | */ |
| 135 | struct mei_message_data { |
| 136 | u32 size; |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 137 | unsigned char *data; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 138 | } __packed; |
| 139 | |
| 140 | |
| 141 | struct mei_cl_cb { |
| 142 | struct list_head cb_list; |
| 143 | enum mei_cb_major_types major_file_operations; |
| 144 | void *file_private; |
| 145 | struct mei_message_data request_buffer; |
| 146 | struct mei_message_data response_buffer; |
| 147 | unsigned long information; |
| 148 | unsigned long read_time; |
| 149 | struct file *file_object; |
| 150 | }; |
| 151 | |
| 152 | /* MEI client instance carried as file->pirvate_data*/ |
| 153 | struct mei_cl { |
| 154 | struct list_head link; |
| 155 | struct mei_device *dev; |
| 156 | enum file_state state; |
| 157 | wait_queue_head_t tx_wait; |
| 158 | wait_queue_head_t rx_wait; |
| 159 | wait_queue_head_t wait; |
| 160 | int read_pending; |
| 161 | int status; |
| 162 | /* ID of client connected */ |
| 163 | u8 host_client_id; |
| 164 | u8 me_client_id; |
| 165 | u8 mei_flow_ctrl_creds; |
| 166 | u8 timer_count; |
| 167 | enum mei_file_transaction_states reading_state; |
| 168 | enum mei_file_transaction_states writing_state; |
| 169 | int sm_state; |
| 170 | struct mei_cl_cb *read_cb; |
| 171 | }; |
| 172 | |
| 173 | struct mei_io_list { |
| 174 | struct mei_cl_cb mei_cb; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 175 | }; |
| 176 | |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 177 | /** |
| 178 | * struct mei_deive - MEI private device struct |
| 179 | * @hbuf_depth - depth of host(write) buffer |
| 180 | */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 181 | struct mei_device { |
| 182 | struct pci_dev *pdev; /* pointer to pci device struct */ |
| 183 | /* |
| 184 | * lists of queues |
| 185 | */ |
| 186 | /* array of pointers to aio lists */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 187 | struct mei_io_list read_list; /* driver read queue */ |
| 188 | struct mei_io_list write_list; /* driver write queue */ |
| 189 | struct mei_io_list write_waiting_list; /* write waiting queue */ |
| 190 | struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */ |
| 191 | struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */ |
| 192 | struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */ |
| 193 | |
| 194 | /* driver managed amthi list for reading completed amthi cmd data */ |
| 195 | struct mei_io_list amthi_read_complete_list; |
| 196 | /* |
| 197 | * list of files |
| 198 | */ |
| 199 | struct list_head file_list; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 200 | long open_handle_count; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 201 | /* |
| 202 | * memory of device |
| 203 | */ |
| 204 | unsigned int mem_base; |
| 205 | unsigned int mem_length; |
| 206 | void __iomem *mem_addr; |
| 207 | /* |
| 208 | * lock for the device |
| 209 | */ |
| 210 | struct mutex device_lock; /* device lock */ |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 211 | struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */ |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 212 | bool recvd_msg; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 213 | /* |
| 214 | * hw states of host and fw(ME) |
| 215 | */ |
| 216 | u32 host_hw_state; |
| 217 | u32 me_hw_state; |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 218 | u8 hbuf_depth; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 219 | /* |
| 220 | * waiting queue for receive message from FW |
| 221 | */ |
| 222 | wait_queue_head_t wait_recvd_msg; |
| 223 | wait_queue_head_t wait_stop_wd; |
| 224 | |
| 225 | /* |
| 226 | * mei device states |
| 227 | */ |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 228 | enum mei_dev_state dev_state; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 229 | enum mei_init_clients_states init_clients_state; |
| 230 | u16 init_clients_timer; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 231 | bool stop; |
| 232 | bool need_reset; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 233 | |
| 234 | u32 extra_write_index; |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 235 | unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 236 | u32 wr_msg_buf[128]; /* used for control messages */ |
| 237 | u32 ext_msg_buf[8]; /* for control responses */ |
| 238 | u32 rd_msg_hdr; |
| 239 | |
| 240 | struct hbm_version version; |
| 241 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 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); |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 245 | u8 me_clients_num; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 246 | u8 me_client_presentation_num; |
| 247 | u8 me_client_index; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 248 | bool mei_host_buffer_is_empty; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 249 | |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 250 | struct mei_cl wd_cl; |
Tomas Winkler | 21c66d1 | 2012-06-19 09:13:37 +0300 | [diff] [blame] | 251 | bool wd_interface_reg; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 252 | bool wd_pending; |
| 253 | bool wd_stopped; |
| 254 | bool wd_bypass; /* if false, don't refresh watchdog ME client */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 255 | u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */ |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame^] | 256 | unsigned char wd_data[MEI_WD_START_MSG_SIZE]; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 257 | |
| 258 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 259 | struct file *iamthif_file_object; |
| 260 | struct mei_cl iamthif_cl; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 261 | struct mei_cl_cb *iamthif_current_cb; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 262 | int iamthif_mtu; |
| 263 | unsigned long iamthif_timer; |
| 264 | u32 iamthif_stall_timer; |
| 265 | unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */ |
| 266 | u32 iamthif_msg_buf_size; |
| 267 | u32 iamthif_msg_buf_index; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 268 | enum iamthif_states iamthif_state; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 269 | bool iamthif_flow_control_pending; |
| 270 | bool iamthif_ioctl; |
| 271 | bool iamthif_canceled; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | |
| 275 | /* |
| 276 | * mei init function prototypes |
| 277 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 278 | struct mei_device *mei_device_init(struct pci_dev *pdev); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 279 | void mei_reset(struct mei_device *dev, int interrupts); |
| 280 | int mei_hw_init(struct mei_device *dev); |
| 281 | int mei_task_initialize_clients(void *data); |
| 282 | int mei_initialize_clients(struct mei_device *dev); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 283 | int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl); |
Tomas Winkler | 106fb49 | 2011-05-25 17:28:20 +0300 | [diff] [blame] | 284 | void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id); |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 285 | void mei_host_init_iamthif(struct mei_device *dev); |
| 286 | void mei_allocate_me_clients_storage(struct mei_device *dev); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 287 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 288 | |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 289 | int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl, |
| 290 | const uuid_le *cguid, u8 host_client_id); |
| 291 | int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid); |
| 292 | int mei_me_cl_by_id(struct mei_device *dev, u8 client_id); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 293 | |
| 294 | /* |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 295 | * MEI IO List Functions |
| 296 | */ |
| 297 | void mei_io_list_init(struct mei_io_list *list); |
| 298 | void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl); |
| 299 | |
| 300 | /* |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 301 | * MEI ME Client Functions |
| 302 | */ |
| 303 | |
| 304 | struct mei_cl *mei_cl_allocate(struct mei_device *dev); |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 305 | void mei_cl_init(struct mei_cl *cl, struct mei_device *dev); |
| 306 | int mei_cl_flush_queues(struct mei_cl *cl); |
| 307 | /** |
| 308 | * mei_cl_cmp_id - tells if file private data have same id |
| 309 | * |
| 310 | * @fe1: private data of 1. file object |
| 311 | * @fe2: private data of 2. file object |
| 312 | * |
| 313 | * returns true - if ids are the same and not NULL |
| 314 | */ |
| 315 | static inline bool mei_cl_cmp_id(const struct mei_cl *cl1, |
| 316 | const struct mei_cl *cl2) |
| 317 | { |
| 318 | return cl1 && cl2 && |
| 319 | (cl1->host_client_id == cl2->host_client_id) && |
| 320 | (cl1->me_client_id == cl2->me_client_id); |
| 321 | } |
| 322 | |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 323 | |
| 324 | |
| 325 | /* |
| 326 | * MEI Host Client Functions |
| 327 | */ |
| 328 | void mei_host_start_message(struct mei_device *dev); |
| 329 | void mei_host_enum_clients_message(struct mei_device *dev); |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 330 | int mei_host_client_properties(struct mei_device *dev); |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 331 | |
| 332 | /* |
| 333 | * MEI interrupt functions prototype |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 334 | */ |
| 335 | irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id); |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 336 | irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id); |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 337 | void mei_timer(struct work_struct *work); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 338 | |
| 339 | /* |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 340 | * MEI input output function prototype |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 341 | */ |
| 342 | int mei_ioctl_connect_client(struct file *file, |
| 343 | struct mei_connect_client_data *data); |
| 344 | |
| 345 | int mei_start_read(struct mei_device *dev, struct mei_cl *cl); |
| 346 | |
| 347 | int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb); |
| 348 | |
| 349 | int amthi_read(struct mei_device *dev, struct file *file, |
| 350 | char __user *ubuf, size_t length, loff_t *offset); |
| 351 | |
| 352 | struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev, |
| 353 | struct file *file); |
| 354 | |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 355 | void mei_run_next_iamthif_cmd(struct mei_device *dev); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 356 | |
| 357 | void mei_free_cb_private(struct mei_cl_cb *priv_cb); |
| 358 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 359 | |
| 360 | /* |
| 361 | * Register Access Function |
| 362 | */ |
| 363 | |
| 364 | /** |
| 365 | * mei_reg_read - Reads 32bit data from the mei device |
| 366 | * |
| 367 | * @dev: the device structure |
| 368 | * @offset: offset from which to read the data |
| 369 | * |
Oren Weil | 92eb401 | 2011-09-07 09:03:08 +0300 | [diff] [blame] | 370 | * returns register value (u32) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 371 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 372 | static inline u32 mei_reg_read(const struct mei_device *dev, |
| 373 | unsigned long offset) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 374 | { |
| 375 | return ioread32(dev->mem_addr + offset); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * mei_reg_write - Writes 32bit data to the mei device |
| 380 | * |
| 381 | * @dev: the device structure |
| 382 | * @offset: offset from which to write the data |
Oren Weil | 92eb401 | 2011-09-07 09:03:08 +0300 | [diff] [blame] | 383 | * @value: register value to write (u32) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 384 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 385 | static inline void mei_reg_write(const struct mei_device *dev, |
| 386 | unsigned long offset, u32 value) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 387 | { |
| 388 | iowrite32(value, dev->mem_addr + offset); |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * mei_hcsr_read - Reads 32bit data from the host CSR |
| 393 | * |
| 394 | * @dev: the device structure |
| 395 | * |
| 396 | * returns the byte read. |
| 397 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 398 | static inline u32 mei_hcsr_read(const struct mei_device *dev) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 399 | { |
| 400 | return mei_reg_read(dev, H_CSR); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * mei_mecsr_read - Reads 32bit data from the ME CSR |
| 405 | * |
| 406 | * @dev: the device structure |
| 407 | * |
| 408 | * returns ME_CSR_HA register value (u32) |
| 409 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 410 | static inline u32 mei_mecsr_read(const struct mei_device *dev) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 411 | { |
| 412 | return mei_reg_read(dev, ME_CSR_HA); |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register |
| 417 | * |
| 418 | * @dev: the device structure |
| 419 | * |
| 420 | * returns ME_CB_RW register value (u32) |
| 421 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 422 | static inline u32 mei_mecbrw_read(const struct mei_device *dev) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 423 | { |
| 424 | return mei_reg_read(dev, ME_CB_RW); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | /* |
| 429 | * mei interface function prototypes |
| 430 | */ |
| 431 | void mei_hcsr_set(struct mei_device *dev); |
| 432 | void mei_csr_clear_his(struct mei_device *dev); |
| 433 | |
| 434 | void mei_enable_interrupts(struct mei_device *dev); |
| 435 | void mei_disable_interrupts(struct mei_device *dev); |
| 436 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 437 | #endif |