[POWERPC] PS3: Bootwrapper improvements
[deliverable/linux.git] / drivers / ps3 / ps3-sys-manager.c
1 /*
2 * PS3 System Manager.
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/workqueue.h>
24 #include <linux/reboot.h>
25
26 #include <asm/firmware.h>
27 #include <asm/ps3.h>
28
29 #include "vuart.h"
30
31 /**
32 * ps3_sys_manager - PS3 system manager driver.
33 *
34 * The system manager provides an asynchronous system event notification
35 * mechanism for reporting events like thermal alert and button presses to
36 * guests. It also provides support to control system shutdown and startup.
37 *
38 * The actual system manager is implemented as an application running in the
39 * system policy module in lpar_1. Guests communicate with the system manager
40 * through port 2 of the vuart using a simple packet message protocol.
41 * Messages are comprised of a fixed field header followed by a message
42 * specific payload.
43 */
44
45 /**
46 * struct ps3_sys_manager_header - System manager message header.
47 * @version: Header version, currently 1.
48 * @size: Header size in bytes, curently 16.
49 * @payload_size: Message payload size in bytes.
50 * @service_id: Message type, one of enum ps3_sys_manager_service_id.
51 * @request_tag: Unique number to identify reply.
52 */
53
54 struct ps3_sys_manager_header {
55 /* version 1 */
56 u8 version;
57 u8 size;
58 u16 reserved_1;
59 u32 payload_size;
60 u16 service_id;
61 u16 reserved_2;
62 u32 request_tag;
63 };
64
65 #define dump_sm_header(_h) _dump_sm_header(_h, __func__, __LINE__)
66 static void __maybe_unused _dump_sm_header(
67 const struct ps3_sys_manager_header *h, const char *func, int line)
68 {
69 pr_debug("%s:%d: version: %xh\n", func, line, h->version);
70 pr_debug("%s:%d: size: %xh\n", func, line, h->size);
71 pr_debug("%s:%d: payload_size: %xh\n", func, line, h->payload_size);
72 pr_debug("%s:%d: service_id: %xh\n", func, line, h->service_id);
73 pr_debug("%s:%d: request_tag: %xh\n", func, line, h->request_tag);
74 }
75
76 /**
77 * @PS3_SM_RX_MSG_LEN_MIN - Shortest received message length.
78 * @PS3_SM_RX_MSG_LEN_MAX - Longest received message length.
79 *
80 * Currently all messages received from the system manager are either
81 * (16 bytes header + 8 bytes payload = 24 bytes) or (16 bytes header
82 * + 16 bytes payload = 32 bytes). This knowlege is used to simplify
83 * the logic.
84 */
85
86 enum {
87 PS3_SM_RX_MSG_LEN_MIN = 24,
88 PS3_SM_RX_MSG_LEN_MAX = 32,
89 };
90
91 /**
92 * enum ps3_sys_manager_service_id - Message header service_id.
93 * @PS3_SM_SERVICE_ID_REQUEST: guest --> sys_manager.
94 * @PS3_SM_SERVICE_ID_REQUEST_ERROR: guest <-- sys_manager.
95 * @PS3_SM_SERVICE_ID_COMMAND: guest <-- sys_manager.
96 * @PS3_SM_SERVICE_ID_RESPONSE: guest --> sys_manager.
97 * @PS3_SM_SERVICE_ID_SET_ATTR: guest --> sys_manager.
98 * @PS3_SM_SERVICE_ID_EXTERN_EVENT: guest <-- sys_manager.
99 * @PS3_SM_SERVICE_ID_SET_NEXT_OP: guest --> sys_manager.
100 *
101 * PS3_SM_SERVICE_ID_REQUEST_ERROR is returned for invalid data values in a
102 * a PS3_SM_SERVICE_ID_REQUEST message. It also seems to be returned when
103 * a REQUEST message is sent at the wrong time.
104 */
105
106 enum ps3_sys_manager_service_id {
107 /* version 1 */
108 PS3_SM_SERVICE_ID_REQUEST = 1,
109 PS3_SM_SERVICE_ID_RESPONSE = 2,
110 PS3_SM_SERVICE_ID_COMMAND = 3,
111 PS3_SM_SERVICE_ID_EXTERN_EVENT = 4,
112 PS3_SM_SERVICE_ID_SET_NEXT_OP = 5,
113 PS3_SM_SERVICE_ID_REQUEST_ERROR = 6,
114 PS3_SM_SERVICE_ID_SET_ATTR = 8,
115 };
116
117 /**
118 * enum ps3_sys_manager_attr - Notification attribute (bit position mask).
119 * @PS3_SM_ATTR_POWER: Power button.
120 * @PS3_SM_ATTR_RESET: Reset button, not available on retail console.
121 * @PS3_SM_ATTR_THERMAL: Sytem thermal alert.
122 * @PS3_SM_ATTR_CONTROLLER: Remote controller event.
123 * @PS3_SM_ATTR_ALL: Logical OR of all.
124 *
125 * The guest tells the system manager which events it is interested in receiving
126 * notice of by sending the system manager a logical OR of notification
127 * attributes via the ps3_sys_manager_send_attr() routine.
128 */
129
130 enum ps3_sys_manager_attr {
131 /* version 1 */
132 PS3_SM_ATTR_POWER = 1,
133 PS3_SM_ATTR_RESET = 2,
134 PS3_SM_ATTR_THERMAL = 4,
135 PS3_SM_ATTR_CONTROLLER = 8, /* bogus? */
136 PS3_SM_ATTR_ALL = 0x0f,
137 };
138
139 /**
140 * enum ps3_sys_manager_event - External event type, reported by system manager.
141 * @PS3_SM_EVENT_POWER_PRESSED: payload.value =
142 * enum ps3_sys_manager_button_event.
143 * @PS3_SM_EVENT_POWER_RELEASED: payload.value = time pressed in millisec.
144 * @PS3_SM_EVENT_RESET_PRESSED: payload.value =
145 * enum ps3_sys_manager_button_event.
146 * @PS3_SM_EVENT_RESET_RELEASED: payload.value = time pressed in millisec.
147 * @PS3_SM_EVENT_THERMAL_ALERT: payload.value = thermal zone id.
148 * @PS3_SM_EVENT_THERMAL_CLEARED: payload.value = thermal zone id.
149 */
150
151 enum ps3_sys_manager_event {
152 /* version 1 */
153 PS3_SM_EVENT_POWER_PRESSED = 3,
154 PS3_SM_EVENT_POWER_RELEASED = 4,
155 PS3_SM_EVENT_RESET_PRESSED = 5,
156 PS3_SM_EVENT_RESET_RELEASED = 6,
157 PS3_SM_EVENT_THERMAL_ALERT = 7,
158 PS3_SM_EVENT_THERMAL_CLEARED = 8,
159 /* no info on controller events */
160 };
161
162 /**
163 * enum ps3_sys_manager_button_event - Button event payload values.
164 * @PS3_SM_BUTTON_EVENT_HARD: Hardware generated event.
165 * @PS3_SM_BUTTON_EVENT_SOFT: Software generated event.
166 */
167
168 enum ps3_sys_manager_button_event {
169 PS3_SM_BUTTON_EVENT_HARD = 0,
170 PS3_SM_BUTTON_EVENT_SOFT = 1,
171 };
172
173 /**
174 * enum ps3_sys_manager_next_op - Operation to perform after lpar is destroyed.
175 */
176
177 enum ps3_sys_manager_next_op {
178 /* version 3 */
179 PS3_SM_NEXT_OP_SYS_SHUTDOWN = 1,
180 PS3_SM_NEXT_OP_SYS_REBOOT = 2,
181 PS3_SM_NEXT_OP_LPAR_REBOOT = 0x82,
182 };
183
184 /**
185 * enum ps3_sys_manager_wake_source - Next-op wakeup source (bit position mask).
186 * @PS3_SM_WAKE_DEFAULT: Disk insert, power button, eject button, IR
187 * controller, and bluetooth controller.
188 * @PS3_SM_WAKE_RTC:
189 * @PS3_SM_WAKE_RTC_ERROR:
190 * @PS3_SM_WAKE_P_O_R: Power on reset.
191 *
192 * Additional wakeup sources when specifying PS3_SM_NEXT_OP_SYS_SHUTDOWN.
193 * The system will always wake from the PS3_SM_WAKE_DEFAULT sources.
194 * Sources listed here are the only ones available to guests in the
195 * other-os lpar.
196 */
197
198 enum ps3_sys_manager_wake_source {
199 /* version 3 */
200 PS3_SM_WAKE_DEFAULT = 0,
201 PS3_SM_WAKE_RTC = 0x00000040,
202 PS3_SM_WAKE_RTC_ERROR = 0x00000080,
203 PS3_SM_WAKE_P_O_R = 0x80000000,
204 };
205
206 /**
207 * enum ps3_sys_manager_cmd - Command from system manager to guest.
208 *
209 * The guest completes the actions needed, then acks or naks the command via
210 * ps3_sys_manager_send_response(). In the case of @PS3_SM_CMD_SHUTDOWN,
211 * the guest must be fully prepared for a system poweroff prior to acking the
212 * command.
213 */
214
215 enum ps3_sys_manager_cmd {
216 /* version 1 */
217 PS3_SM_CMD_SHUTDOWN = 1, /* shutdown guest OS */
218 };
219
220 /**
221 * ps3_sm_force_power_off - Poweroff helper.
222 *
223 * A global variable used to force a poweroff when the power button has
224 * been pressed irrespective of how init handles the ctrl_alt_del signal.
225 *
226 */
227
228 static unsigned int ps3_sm_force_power_off;
229
230 /**
231 * ps3_sys_manager_write - Helper to write a two part message to the vuart.
232 *
233 */
234
235 static int ps3_sys_manager_write(struct ps3_system_bus_device *dev,
236 const struct ps3_sys_manager_header *header, const void *payload)
237 {
238 int result;
239
240 BUG_ON(header->version != 1);
241 BUG_ON(header->size != 16);
242 BUG_ON(header->payload_size != 8 && header->payload_size != 16);
243 BUG_ON(header->service_id > 8);
244
245 result = ps3_vuart_write(dev, header,
246 sizeof(struct ps3_sys_manager_header));
247
248 if (!result)
249 result = ps3_vuart_write(dev, payload, header->payload_size);
250
251 return result;
252 }
253
254 /**
255 * ps3_sys_manager_send_attr - Send a 'set attribute' to the system manager.
256 *
257 */
258
259 static int ps3_sys_manager_send_attr(struct ps3_system_bus_device *dev,
260 enum ps3_sys_manager_attr attr)
261 {
262 struct ps3_sys_manager_header header;
263 struct {
264 u8 version;
265 u8 reserved_1[3];
266 u32 attribute;
267 } payload;
268
269 BUILD_BUG_ON(sizeof(payload) != 8);
270
271 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, attr);
272
273 memset(&header, 0, sizeof(header));
274 header.version = 1;
275 header.size = 16;
276 header.payload_size = 16;
277 header.service_id = PS3_SM_SERVICE_ID_SET_ATTR;
278
279 memset(&payload, 0, sizeof(payload));
280 payload.version = 1;
281 payload.attribute = attr;
282
283 return ps3_sys_manager_write(dev, &header, &payload);
284 }
285
286 /**
287 * ps3_sys_manager_send_next_op - Send a 'set next op' to the system manager.
288 *
289 * Tell the system manager what to do after this lpar is destroyed.
290 */
291
292 static int ps3_sys_manager_send_next_op(struct ps3_system_bus_device *dev,
293 enum ps3_sys_manager_next_op op,
294 enum ps3_sys_manager_wake_source wake_source)
295 {
296 struct ps3_sys_manager_header header;
297 struct {
298 u8 version;
299 u8 type;
300 u8 gos_id;
301 u8 reserved_1;
302 u32 wake_source;
303 u8 reserved_2[8];
304 } payload;
305
306 BUILD_BUG_ON(sizeof(payload) != 16);
307
308 dev_dbg(&dev->core, "%s:%d: (%xh)\n", __func__, __LINE__, op);
309
310 memset(&header, 0, sizeof(header));
311 header.version = 1;
312 header.size = 16;
313 header.payload_size = 16;
314 header.service_id = PS3_SM_SERVICE_ID_SET_NEXT_OP;
315
316 memset(&payload, 0, sizeof(payload));
317 payload.version = 3;
318 payload.type = op;
319 payload.gos_id = 3; /* other os */
320 payload.wake_source = wake_source;
321
322 return ps3_sys_manager_write(dev, &header, &payload);
323 }
324
325 /**
326 * ps3_sys_manager_send_request_shutdown - Send 'request' to the system manager.
327 *
328 * The guest sends this message to request an operation or action of the system
329 * manager. The reply is a command message from the system manager. In the
330 * command handler the guest performs the requested operation. The result of
331 * the command is then communicated back to the system manager with a response
332 * message.
333 *
334 * Currently, the only supported request is the 'shutdown self' request.
335 */
336
337 static int ps3_sys_manager_send_request_shutdown(
338 struct ps3_system_bus_device *dev)
339 {
340 struct ps3_sys_manager_header header;
341 struct {
342 u8 version;
343 u8 type;
344 u8 gos_id;
345 u8 reserved_1[13];
346 } payload;
347
348 BUILD_BUG_ON(sizeof(payload) != 16);
349
350 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
351
352 memset(&header, 0, sizeof(header));
353 header.version = 1;
354 header.size = 16;
355 header.payload_size = 16;
356 header.service_id = PS3_SM_SERVICE_ID_REQUEST;
357
358 memset(&payload, 0, sizeof(payload));
359 payload.version = 1;
360 payload.type = 1; /* shutdown */
361 payload.gos_id = 0; /* self */
362
363 return ps3_sys_manager_write(dev, &header, &payload);
364 }
365
366 /**
367 * ps3_sys_manager_send_response - Send a 'response' to the system manager.
368 * @status: zero = success, others fail.
369 *
370 * The guest sends this message to the system manager to acnowledge success or
371 * failure of a command sent by the system manager.
372 */
373
374 static int ps3_sys_manager_send_response(struct ps3_system_bus_device *dev,
375 u64 status)
376 {
377 struct ps3_sys_manager_header header;
378 struct {
379 u8 version;
380 u8 reserved_1[3];
381 u8 status;
382 u8 reserved_2[11];
383 } payload;
384
385 BUILD_BUG_ON(sizeof(payload) != 16);
386
387 dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
388 (status ? "nak" : "ack"));
389
390 memset(&header, 0, sizeof(header));
391 header.version = 1;
392 header.size = 16;
393 header.payload_size = 16;
394 header.service_id = PS3_SM_SERVICE_ID_RESPONSE;
395
396 memset(&payload, 0, sizeof(payload));
397 payload.version = 1;
398 payload.status = status;
399
400 return ps3_sys_manager_write(dev, &header, &payload);
401 }
402
403 /**
404 * ps3_sys_manager_handle_event - Second stage event msg handler.
405 *
406 */
407
408 static int ps3_sys_manager_handle_event(struct ps3_system_bus_device *dev)
409 {
410 int result;
411 struct {
412 u8 version;
413 u8 type;
414 u8 reserved_1[2];
415 u32 value;
416 u8 reserved_2[8];
417 } event;
418
419 BUILD_BUG_ON(sizeof(event) != 16);
420
421 result = ps3_vuart_read(dev, &event, sizeof(event));
422 BUG_ON(result && "need to retry here");
423
424 if (event.version != 1) {
425 dev_dbg(&dev->core, "%s:%d: unsupported event version (%u)\n",
426 __func__, __LINE__, event.version);
427 return -EIO;
428 }
429
430 switch (event.type) {
431 case PS3_SM_EVENT_POWER_PRESSED:
432 dev_dbg(&dev->core, "%s:%d: POWER_PRESSED (%s)\n",
433 __func__, __LINE__,
434 (event.value == PS3_SM_BUTTON_EVENT_SOFT ? "soft"
435 : "hard"));
436 ps3_sm_force_power_off = 1;
437 /*
438 * A memory barrier is use here to sync memory since
439 * ps3_sys_manager_final_restart() could be called on
440 * another cpu.
441 */
442 wmb();
443 kill_cad_pid(SIGINT, 1); /* ctrl_alt_del */
444 break;
445 case PS3_SM_EVENT_POWER_RELEASED:
446 dev_dbg(&dev->core, "%s:%d: POWER_RELEASED (%u ms)\n",
447 __func__, __LINE__, event.value);
448 break;
449 case PS3_SM_EVENT_RESET_PRESSED:
450 dev_dbg(&dev->core, "%s:%d: RESET_PRESSED (%s)\n",
451 __func__, __LINE__,
452 (event.value == PS3_SM_BUTTON_EVENT_SOFT ? "soft"
453 : "hard"));
454 ps3_sm_force_power_off = 0;
455 /*
456 * A memory barrier is use here to sync memory since
457 * ps3_sys_manager_final_restart() could be called on
458 * another cpu.
459 */
460 wmb();
461 kill_cad_pid(SIGINT, 1); /* ctrl_alt_del */
462 break;
463 case PS3_SM_EVENT_RESET_RELEASED:
464 dev_dbg(&dev->core, "%s:%d: RESET_RELEASED (%u ms)\n",
465 __func__, __LINE__, event.value);
466 break;
467 case PS3_SM_EVENT_THERMAL_ALERT:
468 dev_dbg(&dev->core, "%s:%d: THERMAL_ALERT (zone %u)\n",
469 __func__, __LINE__, event.value);
470 pr_info("PS3 Thermal Alert Zone %u\n", event.value);
471 break;
472 case PS3_SM_EVENT_THERMAL_CLEARED:
473 dev_dbg(&dev->core, "%s:%d: THERMAL_CLEARED (zone %u)\n",
474 __func__, __LINE__, event.value);
475 break;
476 default:
477 dev_dbg(&dev->core, "%s:%d: unknown event (%u)\n",
478 __func__, __LINE__, event.type);
479 return -EIO;
480 }
481
482 return 0;
483 }
484 /**
485 * ps3_sys_manager_handle_cmd - Second stage command msg handler.
486 *
487 * The system manager sends this in reply to a 'request' message from the guest.
488 */
489
490 static int ps3_sys_manager_handle_cmd(struct ps3_system_bus_device *dev)
491 {
492 int result;
493 struct {
494 u8 version;
495 u8 type;
496 u8 reserved_1[14];
497 } cmd;
498
499 BUILD_BUG_ON(sizeof(cmd) != 16);
500
501 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
502
503 result = ps3_vuart_read(dev, &cmd, sizeof(cmd));
504 BUG_ON(result && "need to retry here");
505
506 if (result)
507 return result;
508
509 if (cmd.version != 1) {
510 dev_dbg(&dev->core, "%s:%d: unsupported cmd version (%u)\n",
511 __func__, __LINE__, cmd.version);
512 return -EIO;
513 }
514
515 if (cmd.type != PS3_SM_CMD_SHUTDOWN) {
516 dev_dbg(&dev->core, "%s:%d: unknown cmd (%u)\n",
517 __func__, __LINE__, cmd.type);
518 return -EIO;
519 }
520
521 ps3_sys_manager_send_response(dev, 0);
522 return 0;
523 }
524
525 /**
526 * ps3_sys_manager_handle_msg - First stage msg handler.
527 *
528 * Can be called directly to manually poll vuart and pump message handler.
529 */
530
531 static int ps3_sys_manager_handle_msg(struct ps3_system_bus_device *dev)
532 {
533 int result;
534 struct ps3_sys_manager_header header;
535
536 result = ps3_vuart_read(dev, &header,
537 sizeof(struct ps3_sys_manager_header));
538
539 if (result)
540 return result;
541
542 if (header.version != 1) {
543 dev_dbg(&dev->core, "%s:%d: unsupported header version (%u)\n",
544 __func__, __LINE__, header.version);
545 dump_sm_header(&header);
546 goto fail_header;
547 }
548
549 BUILD_BUG_ON(sizeof(header) != 16);
550
551 if (header.size != 16 || (header.payload_size != 8
552 && header.payload_size != 16)) {
553 dump_sm_header(&header);
554 BUG();
555 }
556
557 switch (header.service_id) {
558 case PS3_SM_SERVICE_ID_EXTERN_EVENT:
559 dev_dbg(&dev->core, "%s:%d: EVENT\n", __func__, __LINE__);
560 return ps3_sys_manager_handle_event(dev);
561 case PS3_SM_SERVICE_ID_COMMAND:
562 dev_dbg(&dev->core, "%s:%d: COMMAND\n", __func__, __LINE__);
563 return ps3_sys_manager_handle_cmd(dev);
564 case PS3_SM_SERVICE_ID_REQUEST_ERROR:
565 dev_dbg(&dev->core, "%s:%d: REQUEST_ERROR\n", __func__,
566 __LINE__);
567 dump_sm_header(&header);
568 break;
569 default:
570 dev_dbg(&dev->core, "%s:%d: unknown service_id (%u)\n",
571 __func__, __LINE__, header.service_id);
572 break;
573 }
574 goto fail_id;
575
576 fail_header:
577 ps3_vuart_clear_rx_bytes(dev, 0);
578 return -EIO;
579 fail_id:
580 ps3_vuart_clear_rx_bytes(dev, header.payload_size);
581 return -EIO;
582 }
583
584 /**
585 * ps3_sys_manager_final_power_off - The final platform machine_power_off routine.
586 *
587 * This routine never returns. The routine disables asynchronous vuart reads
588 * then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
589 * the shutdown command sent from the system manager. Soon after the
590 * acknowledgement is sent the lpar is destroyed by the HV. This routine
591 * should only be called from ps3_power_off() through
592 * ps3_sys_manager_ops.power_off.
593 */
594
595 static void ps3_sys_manager_final_power_off(struct ps3_system_bus_device *dev)
596 {
597 BUG_ON(!dev);
598
599 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
600
601 ps3_vuart_cancel_async(dev);
602
603 ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_SYS_SHUTDOWN,
604 PS3_SM_WAKE_DEFAULT);
605 ps3_sys_manager_send_request_shutdown(dev);
606
607 pr_emerg("System Halted, OK to turn off power\n");
608
609 while (1)
610 ps3_sys_manager_handle_msg(dev);
611 }
612
613 /**
614 * ps3_sys_manager_final_restart - The final platform machine_restart routine.
615 *
616 * This routine never returns. The routine disables asynchronous vuart reads
617 * then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
618 * the shutdown command sent from the system manager. Soon after the
619 * acknowledgement is sent the lpar is destroyed by the HV. This routine
620 * should only be called from ps3_restart() through ps3_sys_manager_ops.restart.
621 */
622
623 static void ps3_sys_manager_final_restart(struct ps3_system_bus_device *dev)
624 {
625 BUG_ON(!dev);
626
627 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
628
629 /* Check if we got here via a power button event. */
630
631 if (ps3_sm_force_power_off) {
632 dev_dbg(&dev->core, "%s:%d: forcing poweroff\n",
633 __func__, __LINE__);
634 ps3_sys_manager_final_power_off(dev);
635 }
636
637 ps3_vuart_cancel_async(dev);
638
639 ps3_sys_manager_send_attr(dev, 0);
640 ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_SYS_REBOOT,
641 PS3_SM_WAKE_DEFAULT);
642 ps3_sys_manager_send_request_shutdown(dev);
643
644 pr_emerg("System Halted, OK to turn off power\n");
645
646 while (1)
647 ps3_sys_manager_handle_msg(dev);
648 }
649
650 /**
651 * ps3_sys_manager_work - Asynchronous read handler.
652 *
653 * Signaled when PS3_SM_RX_MSG_LEN_MIN bytes arrive at the vuart port.
654 */
655
656 static void ps3_sys_manager_work(struct ps3_system_bus_device *dev)
657 {
658 ps3_sys_manager_handle_msg(dev);
659 ps3_vuart_read_async(dev, PS3_SM_RX_MSG_LEN_MIN);
660 }
661
662 static int ps3_sys_manager_probe(struct ps3_system_bus_device *dev)
663 {
664 int result;
665 struct ps3_sys_manager_ops ops;
666
667 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
668
669 ops.power_off = ps3_sys_manager_final_power_off;
670 ops.restart = ps3_sys_manager_final_restart;
671 ops.dev = dev;
672
673 /* ps3_sys_manager_register_ops copies ops. */
674
675 ps3_sys_manager_register_ops(&ops);
676
677 result = ps3_sys_manager_send_attr(dev, PS3_SM_ATTR_ALL);
678 BUG_ON(result);
679
680 result = ps3_vuart_read_async(dev, PS3_SM_RX_MSG_LEN_MIN);
681 BUG_ON(result);
682
683 return result;
684 }
685
686 static int ps3_sys_manager_remove(struct ps3_system_bus_device *dev)
687 {
688 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
689 return 0;
690 }
691
692 static void ps3_sys_manager_shutdown(struct ps3_system_bus_device *dev)
693 {
694 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
695 }
696
697 static struct ps3_vuart_port_driver ps3_sys_manager = {
698 .core.match_id = PS3_MATCH_ID_SYSTEM_MANAGER,
699 .core.core.name = "ps3_sys_manager",
700 .probe = ps3_sys_manager_probe,
701 .remove = ps3_sys_manager_remove,
702 .shutdown = ps3_sys_manager_shutdown,
703 .work = ps3_sys_manager_work,
704 };
705
706 static int __init ps3_sys_manager_init(void)
707 {
708 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
709 return -ENODEV;
710
711 return ps3_vuart_port_driver_register(&ps3_sys_manager);
712 }
713
714 module_init(ps3_sys_manager_init);
715 /* Module remove not supported. */
716
717 MODULE_AUTHOR("Sony Corporation");
718 MODULE_LICENSE("GPL v2");
719 MODULE_DESCRIPTION("PS3 System Manager");
720 MODULE_ALIAS(PS3_MODULE_ALIAS_SYSTEM_MANAGER);
This page took 0.045146 seconds and 6 git commands to generate.