staging: unisys: remove ERRDEV macros
[deliverable/linux.git] / drivers / staging / unisys / uislib / uislib.c
1 /* uislib.c
2 *
3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
15 * details.
16 */
17
18 /* @ALL_INSPECTED */
19 #define EXPORT_SYMTAB
20 #include <linux/kernel.h>
21 #include <linux/highmem.h>
22 #ifdef CONFIG_MODVERSIONS
23 #include <config/modversions.h>
24 #endif
25 #include <linux/module.h>
26 #include <linux/debugfs.h>
27
28 #include <linux/types.h>
29 #include <linux/uuid.h>
30
31 #include <linux/version.h>
32 #include "uniklog.h"
33 #include "diagnostics/appos_subsystems.h"
34 #include "uisutils.h"
35 #include "vbuschannel.h"
36
37 #include <linux/proc_fs.h>
38 #include <linux/uaccess.h> /* for copy_from_user */
39 #include <linux/ctype.h> /* for toupper */
40 #include <linux/list.h>
41
42 #include "sparstop.h"
43 #include "visorchipset.h"
44 #include "version.h"
45 #include "guestlinuxdebug.h"
46
47 #define SET_PROC_OWNER(x, y)
48
49 #define POLLJIFFIES_NORMAL 1
50 /* Choose whether or not you want to wakeup the request-polling thread
51 * after an IO termination:
52 * this is shorter than using __FILE__ (full path name) in
53 * debug/info/error messages
54 */
55 #define CURRENT_FILE_PC UISLIB_PC_uislib_c
56 #define __MYFILE__ "uislib.c"
57
58 /* global function pointers that act as callback functions into virtpcimod */
59 int (*virt_control_chan_func)(struct guest_msgs *);
60
61 static int debug_buf_valid;
62 static char *debug_buf; /* Note this MUST be global,
63 * because the contents must */
64 static unsigned int chipset_inited;
65
66 #define WAIT_ON_CALLBACK(handle) \
67 do { \
68 if (handle) \
69 break; \
70 UIS_THREAD_WAIT; \
71 } while (1)
72
73 static struct bus_info *bus_list;
74 static rwlock_t bus_list_lock;
75 static int bus_list_count; /* number of buses in the list */
76 static int max_bus_count; /* maximum number of buses expected */
77 static u64 phys_data_chan;
78 static int platform_no;
79
80 static struct uisthread_info incoming_ti;
81 static BOOL incoming_started = FALSE;
82 static LIST_HEAD(poll_dev_chan);
83 static unsigned long long tot_moved_to_tail_cnt;
84 static unsigned long long tot_wait_cnt;
85 static unsigned long long tot_wakeup_cnt;
86 static unsigned long long tot_schedule_cnt;
87 static int en_smart_wakeup = 1;
88 static DEFINE_SEMAPHORE(poll_dev_lock); /* unlocked */
89 static DECLARE_WAIT_QUEUE_HEAD(poll_dev_wake_q);
90 static int poll_dev_start;
91
92 #define CALLHOME_PROC_ENTRY_FN "callhome"
93 #define CALLHOME_THROTTLED_PROC_ENTRY_FN "callhome_throttled"
94
95 #define DIR_DEBUGFS_ENTRY "uislib"
96 static struct dentry *dir_debugfs;
97
98 #define PLATFORMNUMBER_DEBUGFS_ENTRY_FN "platform"
99 static struct dentry *platformnumber_debugfs_read;
100
101 #define CYCLES_BEFORE_WAIT_DEBUGFS_ENTRY_FN "cycles_before_wait"
102 static struct dentry *cycles_before_wait_debugfs_read;
103
104 #define SMART_WAKEUP_DEBUGFS_ENTRY_FN "smart_wakeup"
105 static struct dentry *smart_wakeup_debugfs_entry;
106
107 #define INFO_DEBUGFS_ENTRY_FN "info"
108 static struct dentry *info_debugfs_entry;
109
110 static unsigned long long cycles_before_wait, wait_cycles;
111
112 /*****************************************************/
113 /* local functions */
114 /*****************************************************/
115
116 static ssize_t info_debugfs_read(struct file *file, char __user *buf,
117 size_t len, loff_t *offset);
118 static const struct file_operations debugfs_info_fops = {
119 .read = info_debugfs_read,
120 };
121
122 static void
123 init_msg_header(struct controlvm_message *msg, u32 id, uint rsp, uint svr)
124 {
125 memset(msg, 0, sizeof(struct controlvm_message));
126 msg->hdr.id = id;
127 msg->hdr.flags.response_expected = rsp;
128 msg->hdr.flags.server = svr;
129 }
130
131 static __iomem void *init_vbus_channel(u64 ch_addr, u32 ch_bytes)
132 {
133 void __iomem *ch = uislib_ioremap_cache(ch_addr, ch_bytes);
134
135 if (!ch)
136 return NULL;
137
138 if (!SPAR_VBUS_CHANNEL_OK_CLIENT(ch)) {
139 uislib_iounmap(ch);
140 return NULL;
141 }
142 return ch;
143 }
144
145 static int
146 create_bus(struct controlvm_message *msg, char *buf)
147 {
148 u32 bus_no, dev_count;
149 struct bus_info *tmp, *bus;
150 size_t size;
151
152 if (max_bus_count == bus_list_count) {
153 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, max_bus_count,
154 POSTCODE_SEVERITY_ERR);
155 return CONTROLVM_RESP_ERROR_MAX_BUSES;
156 }
157
158 bus_no = msg->cmd.create_bus.bus_no;
159 dev_count = msg->cmd.create_bus.dev_count;
160
161 POSTCODE_LINUX_4(BUS_CREATE_ENTRY_PC, bus_no, dev_count,
162 POSTCODE_SEVERITY_INFO);
163
164 size =
165 sizeof(struct bus_info) +
166 (dev_count * sizeof(struct device_info *));
167 bus = kzalloc(size, GFP_ATOMIC);
168 if (!bus) {
169 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no,
170 POSTCODE_SEVERITY_ERR);
171 return CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
172 }
173
174 /* Currently by default, the bus Number is the GuestHandle.
175 * Configure Bus message can override this.
176 */
177 if (msg->hdr.flags.test_message) {
178 /* This implies we're the IOVM so set guest handle to 0... */
179 bus->guest_handle = 0;
180 bus->bus_no = bus_no;
181 bus->local_vnic = 1;
182 } else {
183 bus->bus_no = bus_no;
184 bus->guest_handle = bus_no;
185 }
186 sprintf(bus->name, "%d", (int)bus->bus_no);
187 bus->device_count = dev_count;
188 bus->device =
189 (struct device_info **)((char *)bus + sizeof(struct bus_info));
190 bus->bus_inst_uuid = msg->cmd.create_bus.bus_inst_uuid;
191 bus->bus_channel_bytes = 0;
192 bus->bus_channel = NULL;
193
194 /* add bus to our bus list - but check for duplicates first */
195 read_lock(&bus_list_lock);
196 for (tmp = bus_list; tmp; tmp = tmp->next) {
197 if (tmp->bus_no == bus->bus_no)
198 break;
199 }
200 read_unlock(&bus_list_lock);
201 if (tmp) {
202 /* found a bus already in the list with same bus_no -
203 * reject add
204 */
205 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->bus_no,
206 POSTCODE_SEVERITY_ERR);
207 kfree(bus);
208 return CONTROLVM_RESP_ERROR_ALREADY_DONE;
209 }
210 if ((msg->cmd.create_bus.channel_addr != 0) &&
211 (msg->cmd.create_bus.channel_bytes != 0)) {
212 bus->bus_channel_bytes = msg->cmd.create_bus.channel_bytes;
213 bus->bus_channel =
214 init_vbus_channel(msg->cmd.create_bus.channel_addr,
215 msg->cmd.create_bus.channel_bytes);
216 }
217 /* the msg is bound for virtpci; send guest_msgs struct to callback */
218 if (!msg->hdr.flags.server) {
219 struct guest_msgs cmd;
220
221 cmd.msgtype = GUEST_ADD_VBUS;
222 cmd.add_vbus.bus_no = bus_no;
223 cmd.add_vbus.chanptr = bus->bus_channel;
224 cmd.add_vbus.dev_count = dev_count;
225 cmd.add_vbus.bus_uuid = msg->cmd.create_bus.bus_data_type_uuid;
226 cmd.add_vbus.instance_uuid = msg->cmd.create_bus.bus_inst_uuid;
227 if (!virt_control_chan_func) {
228 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->bus_no,
229 POSTCODE_SEVERITY_ERR);
230 kfree(bus);
231 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
232 }
233 if (!virt_control_chan_func(&cmd)) {
234 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->bus_no,
235 POSTCODE_SEVERITY_ERR);
236 kfree(bus);
237 return
238 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
239 }
240 }
241
242 /* add bus at the head of our list */
243 write_lock(&bus_list_lock);
244 if (!bus_list) {
245 bus_list = bus;
246 } else {
247 bus->next = bus_list;
248 bus_list = bus;
249 }
250 bus_list_count++;
251 write_unlock(&bus_list_lock);
252
253 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus->bus_no,
254 POSTCODE_SEVERITY_INFO);
255 return CONTROLVM_RESP_SUCCESS;
256 }
257
258 static int
259 destroy_bus(struct controlvm_message *msg, char *buf)
260 {
261 int i;
262 struct bus_info *bus, *prev = NULL;
263 struct guest_msgs cmd;
264 u32 bus_no;
265
266 bus_no = msg->cmd.destroy_bus.bus_no;
267
268 read_lock(&bus_list_lock);
269
270 bus = bus_list;
271 while (bus) {
272 if (bus->bus_no == bus_no)
273 break;
274 prev = bus;
275 bus = bus->next;
276 }
277
278 if (!bus) {
279 read_unlock(&bus_list_lock);
280 return CONTROLVM_RESP_ERROR_ALREADY_DONE;
281 }
282
283 /* verify that this bus has no devices. */
284 for (i = 0; i < bus->device_count; i++) {
285 if (bus->device[i] != NULL) {
286 read_unlock(&bus_list_lock);
287 return CONTROLVM_RESP_ERROR_BUS_DEVICE_ATTACHED;
288 }
289 }
290 read_unlock(&bus_list_lock);
291
292 if (msg->hdr.flags.server)
293 goto remove;
294
295 /* client messages require us to call the virtpci callback associated
296 with this bus. */
297 cmd.msgtype = GUEST_DEL_VBUS;
298 cmd.del_vbus.bus_no = bus_no;
299 if (!virt_control_chan_func)
300 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
301
302 if (!virt_control_chan_func(&cmd))
303 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
304
305 /* finally, remove the bus from the list */
306 remove:
307 write_lock(&bus_list_lock);
308 if (prev) /* not at head */
309 prev->next = bus->next;
310 else
311 bus_list = bus->next;
312 bus_list_count--;
313 write_unlock(&bus_list_lock);
314
315 if (bus->bus_channel) {
316 uislib_iounmap(bus->bus_channel);
317 bus->bus_channel = NULL;
318 }
319
320 kfree(bus);
321 return CONTROLVM_RESP_SUCCESS;
322 }
323
324 static int create_device(struct controlvm_message *msg, char *buf)
325 {
326 struct device_info *dev;
327 struct bus_info *bus;
328 struct guest_msgs cmd;
329 u32 bus_no, dev_no;
330 int result = CONTROLVM_RESP_SUCCESS;
331 u64 min_size = MIN_IO_CHANNEL_SIZE;
332 struct req_handler_info *req_handler;
333
334 bus_no = msg->cmd.create_device.bus_no;
335 dev_no = msg->cmd.create_device.dev_no;
336
337 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no,
338 POSTCODE_SEVERITY_INFO);
339
340 dev = kzalloc(sizeof(*dev), GFP_ATOMIC);
341 if (!dev) {
342 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
343 POSTCODE_SEVERITY_ERR);
344 return CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
345 }
346
347 dev->channel_uuid = msg->cmd.create_device.data_type_uuid;
348 dev->intr = msg->cmd.create_device.intr;
349 dev->channel_addr = msg->cmd.create_device.channel_addr;
350 dev->bus_no = bus_no;
351 dev->dev_no = dev_no;
352 sema_init(&dev->interrupt_callback_lock, 1); /* unlocked */
353 sprintf(dev->devid, "vbus%u:dev%u", (unsigned)bus_no, (unsigned)dev_no);
354 /* map the channel memory for the device. */
355 if (msg->hdr.flags.test_message) {
356 dev->chanptr = (void __iomem *)__va(dev->channel_addr);
357 } else {
358 req_handler = req_handler_find(dev->channel_uuid);
359 if (req_handler)
360 /* generic service handler registered for this
361 * channel
362 */
363 min_size = req_handler->min_channel_bytes;
364 if (min_size > msg->cmd.create_device.channel_bytes) {
365 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no,
366 bus_no, POSTCODE_SEVERITY_ERR);
367 result = CONTROLVM_RESP_ERROR_CHANNEL_SIZE_TOO_SMALL;
368 goto cleanup;
369 }
370 dev->chanptr =
371 uislib_ioremap_cache(dev->channel_addr,
372 msg->cmd.create_device.channel_bytes);
373 if (!dev->chanptr) {
374 result = CONTROLVM_RESP_ERROR_IOREMAP_FAILED;
375 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no,
376 bus_no, POSTCODE_SEVERITY_ERR);
377 goto cleanup;
378 }
379 }
380 dev->instance_uuid = msg->cmd.create_device.dev_inst_uuid;
381 dev->channel_bytes = msg->cmd.create_device.channel_bytes;
382
383 read_lock(&bus_list_lock);
384 for (bus = bus_list; bus; bus = bus->next) {
385 if (bus->bus_no != bus_no)
386 continue;
387 /* make sure the device number is valid */
388 if (dev_no >= bus->device_count) {
389 result = CONTROLVM_RESP_ERROR_MAX_DEVICES;
390 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no,
391 bus_no, POSTCODE_SEVERITY_ERR);
392 read_unlock(&bus_list_lock);
393 goto cleanup;
394 }
395 /* make sure this device is not already set */
396 if (bus->device[dev_no]) {
397 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC,
398 dev_no, bus_no,
399 POSTCODE_SEVERITY_ERR);
400 result = CONTROLVM_RESP_ERROR_ALREADY_DONE;
401 read_unlock(&bus_list_lock);
402 goto cleanup;
403 }
404 read_unlock(&bus_list_lock);
405 /* the msg is bound for virtpci; send
406 * guest_msgs struct to callback
407 */
408 if (msg->hdr.flags.server) {
409 bus->device[dev_no] = dev;
410 POSTCODE_LINUX_4(DEVICE_CREATE_SUCCESS_PC, dev_no,
411 bus_no, POSTCODE_SEVERITY_INFO);
412 return CONTROLVM_RESP_SUCCESS;
413 }
414 if (uuid_le_cmp(dev->channel_uuid,
415 spar_vhba_channel_protocol_uuid) == 0) {
416 wait_for_valid_guid(&((struct channel_header __iomem *)
417 (dev->chanptr))->chtype);
418 if (!SPAR_VHBA_CHANNEL_OK_CLIENT(dev->chanptr)) {
419 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC,
420 dev_no, bus_no,
421 POSTCODE_SEVERITY_ERR);
422 result = CONTROLVM_RESP_ERROR_CHANNEL_INVALID;
423 goto cleanup;
424 }
425 cmd.msgtype = GUEST_ADD_VHBA;
426 cmd.add_vhba.chanptr = dev->chanptr;
427 cmd.add_vhba.bus_no = bus_no;
428 cmd.add_vhba.device_no = dev_no;
429 cmd.add_vhba.instance_uuid = dev->instance_uuid;
430 cmd.add_vhba.intr = dev->intr;
431 } else if (uuid_le_cmp(dev->channel_uuid,
432 spar_vnic_channel_protocol_uuid) == 0) {
433 wait_for_valid_guid(&((struct channel_header __iomem *)
434 (dev->chanptr))->chtype);
435 if (!SPAR_VNIC_CHANNEL_OK_CLIENT(dev->chanptr)) {
436 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC,
437 dev_no, bus_no,
438 POSTCODE_SEVERITY_ERR);
439 result = CONTROLVM_RESP_ERROR_CHANNEL_INVALID;
440 goto cleanup;
441 }
442 cmd.msgtype = GUEST_ADD_VNIC;
443 cmd.add_vnic.chanptr = dev->chanptr;
444 cmd.add_vnic.bus_no = bus_no;
445 cmd.add_vnic.device_no = dev_no;
446 cmd.add_vnic.instance_uuid = dev->instance_uuid;
447 cmd.add_vhba.intr = dev->intr;
448 } else {
449 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no,
450 bus_no, POSTCODE_SEVERITY_ERR);
451 result = CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN;
452 goto cleanup;
453 }
454
455 if (!virt_control_chan_func) {
456 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no,
457 bus_no, POSTCODE_SEVERITY_ERR);
458 result = CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
459 goto cleanup;
460 }
461
462 if (!virt_control_chan_func(&cmd)) {
463 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no,
464 bus_no, POSTCODE_SEVERITY_ERR);
465 result =
466 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
467 goto cleanup;
468 }
469
470 bus->device[dev_no] = dev;
471 POSTCODE_LINUX_4(DEVICE_CREATE_SUCCESS_PC, dev_no,
472 bus_no, POSTCODE_SEVERITY_INFO);
473 return CONTROLVM_RESP_SUCCESS;
474 }
475 read_unlock(&bus_list_lock);
476
477 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
478 POSTCODE_SEVERITY_ERR);
479 result = CONTROLVM_RESP_ERROR_BUS_INVALID;
480
481 cleanup:
482 if (!msg->hdr.flags.test_message) {
483 uislib_iounmap(dev->chanptr);
484 dev->chanptr = NULL;
485 }
486
487 kfree(dev);
488 return result;
489 }
490
491 static int pause_device(struct controlvm_message *msg)
492 {
493 u32 bus_no, dev_no;
494 struct bus_info *bus;
495 struct device_info *dev;
496 struct guest_msgs cmd;
497 int retval = CONTROLVM_RESP_SUCCESS;
498
499 bus_no = msg->cmd.device_change_state.bus_no;
500 dev_no = msg->cmd.device_change_state.dev_no;
501
502 read_lock(&bus_list_lock);
503 for (bus = bus_list; bus; bus = bus->next) {
504 if (bus->bus_no == bus_no) {
505 /* make sure the device number is valid */
506 if (dev_no >= bus->device_count) {
507 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID;
508 } else {
509 /* make sure this device exists */
510 dev = bus->device[dev_no];
511 if (!dev) {
512 retval =
513 CONTROLVM_RESP_ERROR_ALREADY_DONE;
514 }
515 }
516 break;
517 }
518 }
519 if (!bus)
520 retval = CONTROLVM_RESP_ERROR_BUS_INVALID;
521
522 read_unlock(&bus_list_lock);
523 if (retval == CONTROLVM_RESP_SUCCESS) {
524 /* the msg is bound for virtpci; send
525 * guest_msgs struct to callback
526 */
527 if (uuid_le_cmp(dev->channel_uuid,
528 spar_vhba_channel_protocol_uuid) == 0) {
529 cmd.msgtype = GUEST_PAUSE_VHBA;
530 cmd.pause_vhba.chanptr = dev->chanptr;
531 } else if (uuid_le_cmp(dev->channel_uuid,
532 spar_vnic_channel_protocol_uuid) == 0) {
533 cmd.msgtype = GUEST_PAUSE_VNIC;
534 cmd.pause_vnic.chanptr = dev->chanptr;
535 } else {
536 return CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN;
537 }
538 if (!virt_control_chan_func) {
539 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
540 }
541 if (!virt_control_chan_func(&cmd)) {
542 return
543 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
544 }
545 }
546 return retval;
547 }
548
549 static int resume_device(struct controlvm_message *msg)
550 {
551 u32 bus_no, dev_no;
552 struct bus_info *bus;
553 struct device_info *dev;
554 struct guest_msgs cmd;
555 int retval = CONTROLVM_RESP_SUCCESS;
556
557 bus_no = msg->cmd.device_change_state.bus_no;
558 dev_no = msg->cmd.device_change_state.dev_no;
559
560 read_lock(&bus_list_lock);
561 for (bus = bus_list; bus; bus = bus->next) {
562 if (bus->bus_no == bus_no) {
563 /* make sure the device number is valid */
564 if (dev_no >= bus->device_count) {
565 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID;
566 } else {
567 /* make sure this device exists */
568 dev = bus->device[dev_no];
569 if (!dev) {
570 retval =
571 CONTROLVM_RESP_ERROR_ALREADY_DONE;
572 }
573 }
574 break;
575 }
576 }
577
578 if (!bus)
579 retval = CONTROLVM_RESP_ERROR_BUS_INVALID;
580
581 read_unlock(&bus_list_lock);
582 /* the msg is bound for virtpci; send
583 * guest_msgs struct to callback
584 */
585 if (retval == CONTROLVM_RESP_SUCCESS) {
586 if (uuid_le_cmp(dev->channel_uuid,
587 spar_vhba_channel_protocol_uuid) == 0) {
588 cmd.msgtype = GUEST_RESUME_VHBA;
589 cmd.resume_vhba.chanptr = dev->chanptr;
590 } else if (uuid_le_cmp(dev->channel_uuid,
591 spar_vnic_channel_protocol_uuid) == 0) {
592 cmd.msgtype = GUEST_RESUME_VNIC;
593 cmd.resume_vnic.chanptr = dev->chanptr;
594 } else {
595 return CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN;
596 }
597 if (!virt_control_chan_func) {
598 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
599 }
600 if (!virt_control_chan_func(&cmd)) {
601 return
602 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
603 }
604 }
605 return retval;
606 }
607
608 static int destroy_device(struct controlvm_message *msg, char *buf)
609 {
610 u32 bus_no, dev_no;
611 struct bus_info *bus;
612 struct device_info *dev;
613 struct guest_msgs cmd;
614 int retval = CONTROLVM_RESP_SUCCESS;
615
616 bus_no = msg->cmd.destroy_device.bus_no;
617 dev_no = msg->cmd.destroy_device.bus_no;
618
619 read_lock(&bus_list_lock);
620 for (bus = bus_list; bus; bus = bus->next) {
621 if (bus->bus_no == bus_no) {
622 /* make sure the device number is valid */
623 if (dev_no >= bus->device_count) {
624 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID;
625 } else {
626 /* make sure this device exists */
627 dev = bus->device[dev_no];
628 if (!dev) {
629 retval =
630 CONTROLVM_RESP_ERROR_ALREADY_DONE;
631 }
632 }
633 break;
634 }
635 }
636
637 if (!bus)
638 retval = CONTROLVM_RESP_ERROR_BUS_INVALID;
639 read_unlock(&bus_list_lock);
640 if (retval == CONTROLVM_RESP_SUCCESS) {
641 /* the msg is bound for virtpci; send
642 * guest_msgs struct to callback
643 */
644 if (uuid_le_cmp(dev->channel_uuid,
645 spar_vhba_channel_protocol_uuid) == 0) {
646 cmd.msgtype = GUEST_DEL_VHBA;
647 cmd.del_vhba.chanptr = dev->chanptr;
648 } else if (uuid_le_cmp(dev->channel_uuid,
649 spar_vnic_channel_protocol_uuid) == 0) {
650 cmd.msgtype = GUEST_DEL_VNIC;
651 cmd.del_vnic.chanptr = dev->chanptr;
652 } else {
653 return
654 CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN;
655 }
656 if (!virt_control_chan_func) {
657 return
658 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
659 }
660 if (!virt_control_chan_func(&cmd)) {
661 return
662 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
663 }
664 /* you must disable channel interrupts BEFORE you unmap the channel,
665 * because if you unmap first, there may still be some activity going
666 * on which accesses the channel and you will get a "unable to handle
667 * kernel paging request"
668 */
669 if (dev->polling) {
670 uislib_disable_channel_interrupts(bus_no, dev_no);
671 }
672 /* unmap the channel memory for the device. */
673 if (!msg->hdr.flags.test_message) {
674 uislib_iounmap(dev->chanptr);
675 }
676 kfree(dev);
677 bus->device[dev_no] = NULL;
678 }
679 return retval;
680 }
681
682 static int
683 init_chipset(struct controlvm_message *msg, char *buf)
684 {
685 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO);
686
687 max_bus_count = msg->cmd.init_chipset.bus_count;
688 platform_no = msg->cmd.init_chipset.platform_number;
689 phys_data_chan = 0;
690
691 /* We need to make sure we have our functions registered
692 * before processing messages. If we are a test vehicle the
693 * test_message for init_chipset will be set. We can ignore the
694 * waits for the callbacks, since this will be manually entered
695 * from a user. If no test_message is set, we will wait for the
696 * functions.
697 */
698 if (!msg->hdr.flags.test_message)
699 WAIT_ON_CALLBACK(virt_control_chan_func);
700
701 chipset_inited = 1;
702 POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC, POSTCODE_SEVERITY_INFO);
703
704 return CONTROLVM_RESP_SUCCESS;
705 }
706
707 static int delete_bus_glue(u32 bus_no)
708 {
709 struct controlvm_message msg;
710
711 init_msg_header(&msg, CONTROLVM_BUS_DESTROY, 0, 0);
712 msg.cmd.destroy_bus.bus_no = bus_no;
713 if (destroy_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS)
714 return 0;
715 return 1;
716 }
717
718 static int delete_device_glue(u32 bus_no, u32 dev_no)
719 {
720 struct controlvm_message msg;
721
722 init_msg_header(&msg, CONTROLVM_DEVICE_DESTROY, 0, 0);
723 msg.cmd.destroy_device.bus_no = bus_no;
724 msg.cmd.destroy_device.dev_no = dev_no;
725 if (destroy_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS)
726 return 0;
727 return 1;
728 }
729
730 int
731 uislib_client_inject_add_bus(u32 bus_no, uuid_le inst_uuid,
732 u64 channel_addr, ulong n_channel_bytes)
733 {
734 struct controlvm_message msg;
735
736 /* step 0: init the chipset */
737 POSTCODE_LINUX_3(CHIPSET_INIT_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO);
738
739 if (!chipset_inited) {
740 /* step: initialize the chipset */
741 init_msg_header(&msg, CONTROLVM_CHIPSET_INIT, 0, 0);
742 /* this change is needed so that console will come up
743 * OK even when the bus 0 create comes in late. If the
744 * bus 0 create is the first create, then the add_vnic
745 * will work fine, but if the bus 0 create arrives
746 * after number 4, then the add_vnic will fail, and the
747 * ultraboot will fail.
748 */
749 msg.cmd.init_chipset.bus_count = 23;
750 msg.cmd.init_chipset.switch_count = 0;
751 if (init_chipset(&msg, NULL) != CONTROLVM_RESP_SUCCESS)
752 return 0;
753 POSTCODE_LINUX_3(CHIPSET_INIT_EXIT_PC, bus_no,
754 POSTCODE_SEVERITY_INFO);
755 }
756
757 /* step 1: create a bus */
758 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no,
759 POSTCODE_SEVERITY_WARNING);
760 init_msg_header(&msg, CONTROLVM_BUS_CREATE, 0, 0);
761 msg.cmd.create_bus.bus_no = bus_no;
762 msg.cmd.create_bus.dev_count = 23; /* devNo+1; */
763 msg.cmd.create_bus.channel_addr = channel_addr;
764 msg.cmd.create_bus.channel_bytes = n_channel_bytes;
765 if (create_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
766 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no,
767 POSTCODE_SEVERITY_ERR);
768 return 0;
769 }
770 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO);
771
772 return 1;
773 }
774 EXPORT_SYMBOL_GPL(uislib_client_inject_add_bus);
775
776 int
777 uislib_client_inject_del_bus(u32 bus_no)
778 {
779 return delete_bus_glue(bus_no);
780 }
781 EXPORT_SYMBOL_GPL(uislib_client_inject_del_bus);
782
783 int
784 uislib_client_inject_pause_vhba(u32 bus_no, u32 dev_no)
785 {
786 struct controlvm_message msg;
787 int rc;
788
789 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0);
790 msg.cmd.device_change_state.bus_no = bus_no;
791 msg.cmd.device_change_state.dev_no = dev_no;
792 msg.cmd.device_change_state.state = segment_state_standby;
793 rc = pause_device(&msg);
794 if (rc != CONTROLVM_RESP_SUCCESS)
795 return rc;
796 return 0;
797 }
798 EXPORT_SYMBOL_GPL(uislib_client_inject_pause_vhba);
799
800 int
801 uislib_client_inject_resume_vhba(u32 bus_no, u32 dev_no)
802 {
803 struct controlvm_message msg;
804 int rc;
805
806 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0);
807 msg.cmd.device_change_state.bus_no = bus_no;
808 msg.cmd.device_change_state.dev_no = dev_no;
809 msg.cmd.device_change_state.state = segment_state_running;
810 rc = resume_device(&msg);
811 if (rc != CONTROLVM_RESP_SUCCESS)
812 return rc;
813 return 0;
814 }
815 EXPORT_SYMBOL_GPL(uislib_client_inject_resume_vhba);
816
817 int
818 uislib_client_inject_add_vhba(u32 bus_no, u32 dev_no,
819 u64 phys_chan_addr, u32 chan_bytes,
820 int is_test_addr, uuid_le inst_uuid,
821 struct irq_info *intr)
822 {
823 struct controlvm_message msg;
824
825 /* chipset init'ed with bus bus has been previously created -
826 * Verify it still exists step 2: create the VHBA device on the
827 * bus
828 */
829 POSTCODE_LINUX_4(VHBA_CREATE_ENTRY_PC, dev_no, bus_no,
830 POSTCODE_SEVERITY_INFO);
831
832 init_msg_header(&msg, CONTROLVM_DEVICE_CREATE, 0, 0);
833 if (is_test_addr)
834 /* signify that the physical channel address does NOT
835 * need to be ioremap()ed
836 */
837 msg.hdr.flags.test_message = 1;
838 msg.cmd.create_device.bus_no = bus_no;
839 msg.cmd.create_device.dev_no = dev_no;
840 msg.cmd.create_device.dev_inst_uuid = inst_uuid;
841 if (intr)
842 msg.cmd.create_device.intr = *intr;
843 else
844 memset(&msg.cmd.create_device.intr, 0,
845 sizeof(struct irq_info));
846 msg.cmd.create_device.channel_addr = phys_chan_addr;
847 if (chan_bytes < MIN_IO_CHANNEL_SIZE) {
848 POSTCODE_LINUX_4(VHBA_CREATE_FAILURE_PC, chan_bytes,
849 MIN_IO_CHANNEL_SIZE, POSTCODE_SEVERITY_ERR);
850 return 0;
851 }
852 msg.cmd.create_device.channel_bytes = chan_bytes;
853 msg.cmd.create_device.data_type_uuid = spar_vhba_channel_protocol_uuid;
854 if (create_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
855 POSTCODE_LINUX_4(VHBA_CREATE_FAILURE_PC, dev_no, bus_no,
856 POSTCODE_SEVERITY_ERR);
857 return 0;
858 }
859 POSTCODE_LINUX_4(VHBA_CREATE_SUCCESS_PC, dev_no, bus_no,
860 POSTCODE_SEVERITY_INFO);
861 return 1;
862 }
863 EXPORT_SYMBOL_GPL(uislib_client_inject_add_vhba);
864
865 int
866 uislib_client_inject_del_vhba(u32 bus_no, u32 dev_no)
867 {
868 return delete_device_glue(bus_no, dev_no);
869 }
870 EXPORT_SYMBOL_GPL(uislib_client_inject_del_vhba);
871
872 int
873 uislib_client_inject_add_vnic(u32 bus_no, u32 dev_no,
874 u64 phys_chan_addr, u32 chan_bytes,
875 int is_test_addr, uuid_le inst_uuid,
876 struct irq_info *intr)
877 {
878 struct controlvm_message msg;
879
880 /* chipset init'ed with bus bus has been previously created -
881 * Verify it still exists step 2: create the VNIC device on the
882 * bus
883 */
884 POSTCODE_LINUX_4(VNIC_CREATE_ENTRY_PC, dev_no, bus_no,
885 POSTCODE_SEVERITY_INFO);
886
887 init_msg_header(&msg, CONTROLVM_DEVICE_CREATE, 0, 0);
888 if (is_test_addr)
889 /* signify that the physical channel address does NOT
890 * need to be ioremap()ed
891 */
892 msg.hdr.flags.test_message = 1;
893 msg.cmd.create_device.bus_no = bus_no;
894 msg.cmd.create_device.dev_no = dev_no;
895 msg.cmd.create_device.dev_inst_uuid = inst_uuid;
896 if (intr)
897 msg.cmd.create_device.intr = *intr;
898 else
899 memset(&msg.cmd.create_device.intr, 0,
900 sizeof(struct irq_info));
901 msg.cmd.create_device.channel_addr = phys_chan_addr;
902 if (chan_bytes < MIN_IO_CHANNEL_SIZE) {
903 POSTCODE_LINUX_4(VNIC_CREATE_FAILURE_PC, chan_bytes,
904 MIN_IO_CHANNEL_SIZE, POSTCODE_SEVERITY_ERR);
905 return 0;
906 }
907 msg.cmd.create_device.channel_bytes = chan_bytes;
908 msg.cmd.create_device.data_type_uuid = spar_vnic_channel_protocol_uuid;
909 if (create_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
910 POSTCODE_LINUX_4(VNIC_CREATE_FAILURE_PC, dev_no, bus_no,
911 POSTCODE_SEVERITY_ERR);
912 return 0;
913 }
914
915 POSTCODE_LINUX_4(VNIC_CREATE_SUCCESS_PC, dev_no, bus_no,
916 POSTCODE_SEVERITY_INFO);
917 return 1;
918 }
919 EXPORT_SYMBOL_GPL(uislib_client_inject_add_vnic);
920
921 int
922 uislib_client_inject_pause_vnic(u32 bus_no, u32 dev_no)
923 {
924 struct controlvm_message msg;
925 int rc;
926
927 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0);
928 msg.cmd.device_change_state.bus_no = bus_no;
929 msg.cmd.device_change_state.dev_no = dev_no;
930 msg.cmd.device_change_state.state = segment_state_standby;
931 rc = pause_device(&msg);
932 if (rc != CONTROLVM_RESP_SUCCESS) {
933 return -1;
934 }
935 return 0;
936 }
937 EXPORT_SYMBOL_GPL(uislib_client_inject_pause_vnic);
938
939 int
940 uislib_client_inject_resume_vnic(u32 bus_no, u32 dev_no)
941 {
942 struct controlvm_message msg;
943 int rc;
944
945 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0);
946 msg.cmd.device_change_state.bus_no = bus_no;
947 msg.cmd.device_change_state.dev_no = dev_no;
948 msg.cmd.device_change_state.state = segment_state_running;
949 rc = resume_device(&msg);
950 if (rc != CONTROLVM_RESP_SUCCESS)
951 return -1;
952 return 0;
953 }
954 EXPORT_SYMBOL_GPL(uislib_client_inject_resume_vnic);
955
956 int
957 uislib_client_inject_del_vnic(u32 bus_no, u32 dev_no)
958 {
959 return delete_device_glue(bus_no, dev_no);
960 }
961 EXPORT_SYMBOL_GPL(uislib_client_inject_del_vnic);
962
963 void *
964 uislib_cache_alloc(struct kmem_cache *cur_pool, char *fn, int ln)
965 {
966 /* __GFP_NORETRY means "ok to fail", meaning kmalloc() can
967 * return NULL. If you do NOT specify __GFP_NORETRY, Linux
968 * will go to extreme measures to get memory for you (like,
969 * invoke oom killer), which will probably cripple the system.
970 */
971 void *p = kmem_cache_alloc(cur_pool, GFP_ATOMIC | __GFP_NORETRY);
972
973 if (p == NULL)
974 return NULL;
975 return p;
976 }
977 EXPORT_SYMBOL_GPL(uislib_cache_alloc);
978
979 void
980 uislib_cache_free(struct kmem_cache *cur_pool, void *p, char *fn, int ln)
981 {
982 if (p == NULL)
983 return;
984 kmem_cache_free(cur_pool, p);
985 }
986 EXPORT_SYMBOL_GPL(uislib_cache_free);
987
988 /*****************************************************/
989 /* proc filesystem callback functions */
990 /*****************************************************/
991
992 #define PLINE(...) uisutil_add_proc_line_ex(&tot, buff, \
993 buff_len, __VA_ARGS__)
994
995 static int
996 info_debugfs_read_helper(char **buff, int *buff_len)
997 {
998 int i, tot = 0;
999 struct bus_info *bus;
1000
1001 if (PLINE("\nBuses:\n") < 0)
1002 goto err_done;
1003
1004 read_lock(&bus_list_lock);
1005 for (bus = bus_list; bus; bus = bus->next) {
1006 if (PLINE(" bus=0x%p, busNo=%d, deviceCount=%d\n",
1007 bus, bus->bus_no, bus->device_count) < 0)
1008 goto err_done_unlock;
1009
1010 if (PLINE(" Devices:\n") < 0)
1011 goto err_done_unlock;
1012
1013 for (i = 0; i < bus->device_count; i++) {
1014 if (bus->device[i]) {
1015 if (PLINE(" busNo %d, device[%i]: 0x%p, chanptr=0x%p, swtch=0x%p\n",
1016 bus->bus_no, i, bus->device[i],
1017 bus->device[i]->chanptr,
1018 bus->device[i]->swtch) < 0)
1019 goto err_done_unlock;
1020
1021 if (PLINE(" first_busy_cnt=%llu, moved_to_tail_cnt=%llu, last_on_list_cnt=%llu\n",
1022 bus->device[i]->first_busy_cnt,
1023 bus->device[i]->moved_to_tail_cnt,
1024 bus->device[i]->last_on_list_cnt) < 0)
1025 goto err_done_unlock;
1026 }
1027 }
1028 }
1029 read_unlock(&bus_list_lock);
1030
1031 if (PLINE("UisUtils_Registered_Services: %d\n",
1032 atomic_read(&uisutils_registered_services)) < 0)
1033 goto err_done;
1034 if (PLINE("cycles_before_wait %llu wait_cycles:%llu\n",
1035 cycles_before_wait, wait_cycles) < 0)
1036 goto err_done;
1037 if (PLINE("tot_wakeup_cnt %llu:tot_wait_cnt %llu:tot_schedule_cnt %llu\n",
1038 tot_wakeup_cnt, tot_wait_cnt, tot_schedule_cnt) < 0)
1039 goto err_done;
1040 if (PLINE("en_smart_wakeup %d\n", en_smart_wakeup) < 0)
1041 goto err_done;
1042 if (PLINE("tot_moved_to_tail_cnt %llu\n", tot_moved_to_tail_cnt) < 0)
1043 goto err_done;
1044
1045 return tot;
1046
1047 err_done_unlock:
1048 read_unlock(&bus_list_lock);
1049 err_done:
1050 return -1;
1051 }
1052
1053 static ssize_t info_debugfs_read(struct file *file, char __user *buf,
1054 size_t len, loff_t *offset)
1055 {
1056 char *temp;
1057 int total_bytes = 0;
1058 int remaining_bytes = PROC_READ_BUFFER_SIZE;
1059
1060 /* *start = buf; */
1061 if (debug_buf == NULL) {
1062 debug_buf = vmalloc(PROC_READ_BUFFER_SIZE);
1063
1064 if (debug_buf == NULL)
1065 return -ENOMEM;
1066 }
1067
1068 temp = debug_buf;
1069
1070 if ((*offset == 0) || (!debug_buf_valid)) {
1071 /* if the read fails, then -1 will be returned */
1072 total_bytes = info_debugfs_read_helper(&temp, &remaining_bytes);
1073 debug_buf_valid = 1;
1074 } else {
1075 total_bytes = strlen(debug_buf);
1076 }
1077
1078 return simple_read_from_buffer(buf, len, offset,
1079 debug_buf, total_bytes);
1080 }
1081
1082 static struct device_info *find_dev(u32 bus_no, u32 dev_no)
1083 {
1084 struct bus_info *bus;
1085 struct device_info *dev = NULL;
1086
1087 read_lock(&bus_list_lock);
1088 for (bus = bus_list; bus; bus = bus->next) {
1089 if (bus->bus_no == bus_no) {
1090 /* make sure the device number is valid */
1091 if (dev_no >= bus->device_count)
1092 break;
1093 dev = bus->device[dev_no];
1094 break;
1095 }
1096 }
1097 read_unlock(&bus_list_lock);
1098 return dev;
1099 }
1100
1101 /* This thread calls the "interrupt" function for each device that has
1102 * enabled such using uislib_enable_channel_interrupts(). The "interrupt"
1103 * function typically reads and processes the devices's channel input
1104 * queue. This thread repeatedly does this, until the thread is told to stop
1105 * (via uisthread_stop()). Sleeping rules:
1106 * - If we have called the "interrupt" function for all devices, and all of
1107 * them have reported "nothing processed" (returned 0), then we will go to
1108 * sleep for a maximum of POLLJIFFIES_NORMAL jiffies.
1109 * - If anyone calls uislib_force_channel_interrupt(), the above jiffy
1110 * sleep will be interrupted, and we will resume calling the "interrupt"
1111 * function for all devices.
1112 * - The list of devices is dynamically re-ordered in order to
1113 * attempt to preserve fairness. Whenever we spin thru the list of
1114 * devices and call the dev->interrupt() function, if we find
1115 * devices which report that there is still more work to do, the
1116 * the first such device we find is moved to the end of the device
1117 * list. This ensures that extremely busy devices don't starve out
1118 * less-busy ones.
1119 *
1120 */
1121 static int process_incoming(void *v)
1122 {
1123 unsigned long long cur_cycles, old_cycles, idle_cycles, delta_cycles;
1124 struct list_head *new_tail = NULL;
1125 int i;
1126
1127 UIS_DAEMONIZE("dev_incoming");
1128 for (i = 0; i < 16; i++) {
1129 old_cycles = get_cycles();
1130 wait_event_timeout(poll_dev_wake_q,
1131 0, POLLJIFFIES_NORMAL);
1132 cur_cycles = get_cycles();
1133 if (wait_cycles == 0) {
1134 wait_cycles = (cur_cycles - old_cycles);
1135 } else {
1136 if (wait_cycles < (cur_cycles - old_cycles))
1137 wait_cycles = (cur_cycles - old_cycles);
1138 }
1139 }
1140 cycles_before_wait = wait_cycles;
1141 idle_cycles = 0;
1142 poll_dev_start = 0;
1143 while (1) {
1144 struct list_head *lelt, *tmp;
1145 struct device_info *dev = NULL;
1146
1147 /* poll each channel for input */
1148 down(&poll_dev_lock);
1149 new_tail = NULL;
1150 list_for_each_safe(lelt, tmp, &poll_dev_chan) {
1151 int rc = 0;
1152
1153 dev = list_entry(lelt, struct device_info,
1154 list_polling_device_channels);
1155 down(&dev->interrupt_callback_lock);
1156 if (dev->interrupt)
1157 rc = dev->interrupt(dev->interrupt_context);
1158 else
1159 continue;
1160 up(&dev->interrupt_callback_lock);
1161 if (rc) {
1162 /* dev->interrupt returned, but there
1163 * is still more work to do.
1164 * Reschedule work to occur as soon as
1165 * possible. */
1166 idle_cycles = 0;
1167 if (new_tail == NULL) {
1168 dev->first_busy_cnt++;
1169 if (!
1170 (list_is_last
1171 (lelt,
1172 &poll_dev_chan))) {
1173 new_tail = lelt;
1174 dev->moved_to_tail_cnt++;
1175 } else {
1176 dev->last_on_list_cnt++;
1177 }
1178 }
1179 }
1180 if (kthread_should_stop())
1181 break;
1182 }
1183 if (new_tail != NULL) {
1184 tot_moved_to_tail_cnt++;
1185 list_move_tail(new_tail, &poll_dev_chan);
1186 }
1187 up(&poll_dev_lock);
1188 cur_cycles = get_cycles();
1189 delta_cycles = cur_cycles - old_cycles;
1190 old_cycles = cur_cycles;
1191
1192 /* At this point, we have scanned thru all of the
1193 * channels, and at least one of the following is true:
1194 * - there is no input waiting on any of the channels
1195 * - we have received a signal to stop this thread
1196 */
1197 if (kthread_should_stop())
1198 break;
1199 if (en_smart_wakeup == 0xFF) {
1200 break;
1201 }
1202 /* wait for POLLJIFFIES_NORMAL jiffies, or until
1203 * someone wakes up poll_dev_wake_q,
1204 * whichever comes first only do a wait when we have
1205 * been idle for cycles_before_wait cycles.
1206 */
1207 if (idle_cycles > cycles_before_wait) {
1208 poll_dev_start = 0;
1209 tot_wait_cnt++;
1210 wait_event_timeout(poll_dev_wake_q,
1211 poll_dev_start,
1212 POLLJIFFIES_NORMAL);
1213 poll_dev_start = 1;
1214 } else {
1215 tot_schedule_cnt++;
1216 schedule();
1217 idle_cycles = idle_cycles + delta_cycles;
1218 }
1219 }
1220 complete_and_exit(&incoming_ti.has_stopped, 0);
1221 }
1222
1223 static BOOL
1224 initialize_incoming_thread(void)
1225 {
1226 if (incoming_started)
1227 return TRUE;
1228 if (!uisthread_start(&incoming_ti,
1229 &process_incoming, NULL, "dev_incoming")) {
1230 return FALSE;
1231 }
1232 incoming_started = TRUE;
1233 return TRUE;
1234 }
1235
1236 /* Add a new device/channel to the list being processed by
1237 * process_incoming().
1238 * <interrupt> - indicates the function to call periodically.
1239 * <interrupt_context> - indicates the data to pass to the <interrupt>
1240 * function.
1241 */
1242 void
1243 uislib_enable_channel_interrupts(u32 bus_no, u32 dev_no,
1244 int (*interrupt)(void *),
1245 void *interrupt_context)
1246 {
1247 struct device_info *dev;
1248
1249 dev = find_dev(bus_no, dev_no);
1250 if (!dev)
1251 return;
1252
1253 down(&poll_dev_lock);
1254 initialize_incoming_thread();
1255 dev->interrupt = interrupt;
1256 dev->interrupt_context = interrupt_context;
1257 dev->polling = TRUE;
1258 list_add_tail(&dev->list_polling_device_channels,
1259 &poll_dev_chan);
1260 up(&poll_dev_lock);
1261 }
1262 EXPORT_SYMBOL_GPL(uislib_enable_channel_interrupts);
1263
1264 /* Remove a device/channel from the list being processed by
1265 * process_incoming().
1266 */
1267 void
1268 uislib_disable_channel_interrupts(u32 bus_no, u32 dev_no)
1269 {
1270 struct device_info *dev;
1271
1272 dev = find_dev(bus_no, dev_no);
1273 if (!dev)
1274 return;
1275 down(&poll_dev_lock);
1276 list_del(&dev->list_polling_device_channels);
1277 dev->polling = FALSE;
1278 dev->interrupt = NULL;
1279 up(&poll_dev_lock);
1280 }
1281 EXPORT_SYMBOL_GPL(uislib_disable_channel_interrupts);
1282
1283 static void
1284 do_wakeup_polling_device_channels(struct work_struct *dummy)
1285 {
1286 if (!poll_dev_start) {
1287 poll_dev_start = 1;
1288 wake_up(&poll_dev_wake_q);
1289 }
1290 }
1291
1292 static DECLARE_WORK(work_wakeup_polling_device_channels,
1293 do_wakeup_polling_device_channels);
1294
1295 /* Call this function when you want to send a hint to process_incoming() that
1296 * your device might have more requests.
1297 */
1298 void
1299 uislib_force_channel_interrupt(u32 bus_no, u32 dev_no)
1300 {
1301 if (en_smart_wakeup == 0)
1302 return;
1303 if (poll_dev_start)
1304 return;
1305 /* The point of using schedule_work() instead of just doing
1306 * the work inline is to force a slight delay before waking up
1307 * the process_incoming() thread.
1308 */
1309 tot_wakeup_cnt++;
1310 schedule_work(&work_wakeup_polling_device_channels);
1311 }
1312 EXPORT_SYMBOL_GPL(uislib_force_channel_interrupt);
1313
1314 /*****************************************************/
1315 /* Module Init & Exit functions */
1316 /*****************************************************/
1317
1318 static int __init
1319 uislib_mod_init(void)
1320 {
1321 if (!unisys_spar_platform)
1322 return -ENODEV;
1323
1324 /* initialize global pointers to NULL */
1325 bus_list = NULL;
1326 bus_list_count = 0;
1327 max_bus_count = 0;
1328 rwlock_init(&bus_list_lock);
1329 virt_control_chan_func = NULL;
1330
1331 /* Issue VMCALL_GET_CONTROLVM_ADDR to get CtrlChanPhysAddr and
1332 * then map this physical address to a virtual address. */
1333 POSTCODE_LINUX_2(DRIVER_ENTRY_PC, POSTCODE_SEVERITY_INFO);
1334
1335 dir_debugfs = debugfs_create_dir(DIR_DEBUGFS_ENTRY, NULL);
1336 if (dir_debugfs) {
1337 info_debugfs_entry = debugfs_create_file(
1338 INFO_DEBUGFS_ENTRY_FN, 0444, dir_debugfs, NULL,
1339 &debugfs_info_fops);
1340
1341 platformnumber_debugfs_read = debugfs_create_u32(
1342 PLATFORMNUMBER_DEBUGFS_ENTRY_FN, 0444, dir_debugfs,
1343 &platform_no);
1344
1345 cycles_before_wait_debugfs_read = debugfs_create_u64(
1346 CYCLES_BEFORE_WAIT_DEBUGFS_ENTRY_FN, 0666, dir_debugfs,
1347 &cycles_before_wait);
1348
1349 smart_wakeup_debugfs_entry = debugfs_create_bool(
1350 SMART_WAKEUP_DEBUGFS_ENTRY_FN, 0666, dir_debugfs,
1351 &en_smart_wakeup);
1352 }
1353
1354 POSTCODE_LINUX_3(DRIVER_EXIT_PC, 0, POSTCODE_SEVERITY_INFO);
1355 return 0;
1356 }
1357
1358 static void __exit
1359 uislib_mod_exit(void)
1360 {
1361 if (debug_buf) {
1362 vfree(debug_buf);
1363 debug_buf = NULL;
1364 }
1365
1366 debugfs_remove(info_debugfs_entry);
1367 debugfs_remove(smart_wakeup_debugfs_entry);
1368 debugfs_remove(cycles_before_wait_debugfs_read);
1369 debugfs_remove(platformnumber_debugfs_read);
1370 debugfs_remove(dir_debugfs);
1371 }
1372
1373 module_init(uislib_mod_init);
1374 module_exit(uislib_mod_exit);
1375
1376 MODULE_LICENSE("GPL");
1377 MODULE_AUTHOR("Usha Srinivasan");
1378 MODULE_ALIAS("uislib");
1379 /* this is extracted during depmod and kept in modules.dep */
This page took 0.088688 seconds and 5 git commands to generate.