3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; version 2 of the License.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "ps3hvc_dev.h"
25 #define PS3HVC_HVCALL_VERSION "0.0.1"
36 static struct option long_opts
[] = {
37 { "help", no_argument
, NULL
, 'h' },
38 { "verbose", no_argument
, NULL
, 'v' },
39 { "version", no_argument
, NULL
, 'V' },
46 static void usage(void) {
48 "Usage: ps3hvc_hvcall [OPTIONS] DEVICE COMMAND [ARGS]\n"
51 " -h, --help Show this message and exit\n"
52 " -v, --verbose Increase verbosity\n"
53 " -V, --version Show version information and exit\n"
55 " undocumented_function_8 Returns current uptime\n"
56 " construct_event_receive_port Constructs outlet\n"
57 " destruct_event_receive_port OUTLETID Destructs outlet\n"
58 " get_repo_node_val LPARID KEY0 KEY1 KEY2 KEY3 Returns repository node value\n"
59 " panic ARG1 Panics\n"
61 "Simple example: Reboot after panic:\n"
62 " ps3hvc_hvcall /dev/ps3hvc panic 1\n");
68 static void version(void)
71 "ps3hvc_hvcall " PS3HVC_HVCALL_VERSION
"\n"
72 "Copyright (C) 2011 graf_chokolo <grafchokolo@googlemail.com>\n"
73 "This is free software. You may redistribute copies of it "
74 "under the terms of\n"
75 "the GNU General Public License 2 "
76 "<http://www.gnu.org/licenses/gpl2.html>.\n"
77 "There is NO WARRANTY, to the extent permitted by law.\n");
83 static int process_opts(int argc
, char **argv
, struct opts
*opts
)
87 while ((c
= getopt_long(argc
, argv
, "hvV", long_opts
, NULL
)) != -1) {
103 fprintf(stderr
, "Invalid command option: %c\n", c
);
108 if (optind
>= argc
) {
109 fprintf(stderr
, "No device specified\n");
113 opts
->device_name
= argv
[optind
];
116 if (optind
>= argc
) {
117 fprintf(stderr
, "No command specified\n");
121 opts
->cmd
= argv
[optind
];
128 * cmd_undocumented_function_8
130 static int cmd_undocumented_function_8(int fd
, struct opts
*opts
, int argc
, char **argv
)
136 error
= ps3hvc_dev_hvcall(fd
, PS3HVC_HVCALL_UNDOCUMENTED_FUNCTION_8
, 0, 1, args
, &result
);
139 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
141 fprintf(stderr
, "hvcall result: 0x%016lx\n", result
);
143 fprintf(stdout
, "0x%016lx\n", args
[0]);
149 * cmd_construct_event_receive_port
151 static int cmd_construct_event_receive_port(int fd
, struct opts
*opts
, int argc
, char **argv
)
157 error
= ps3hvc_dev_hvcall(fd
, PS3HVC_HVCALL_CONSTRUCT_EVENT_RECEIVE_PORT
, 0, 1, args
, &result
);
160 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
162 fprintf(stderr
, "hvcall result: 0x%016lx\n", result
);
164 fprintf(stdout
, "0x%016lx\n", args
[0]);
170 * cmd_destruct_event_receive_port
172 static int cmd_destruct_event_receive_port(int fd
, struct opts
*opts
, int argc
, char **argv
)
180 if (optind
>= argc
) {
181 fprintf(stderr
, "No outlet identifier specified\n");
185 outletid
= strtoull(argv
[optind
], &endptr
, 0);
186 if (*endptr
!= '\0') {
187 fprintf(stderr
, "Invalid outlet identifier specified: %s\n", argv
[optind
]);
195 error
= ps3hvc_dev_hvcall(fd
, PS3HVC_HVCALL_DESTRUCT_EVENT_RECEIVE_PORT
, 1, 0, args
, &result
);
198 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
200 fprintf(stderr
, "hvcall result: 0x%016lx\n", result
);
206 * cmd_get_repo_node_val
208 static int cmd_get_repo_node_val(int fd
, struct opts
*opts
, int argc
, char **argv
)
210 uint64_t lpar_id
, key
[4];
216 if (optind
>= argc
) {
217 fprintf(stderr
, "No LPAR identifier specified\n");
221 lpar_id
= strtoull(argv
[optind
], &endptr
, 0);
222 if (*endptr
!= '\0') {
223 fprintf(stderr
, "Invalid LPAR identifier specified: %s\n", argv
[optind
]);
229 for (i
= 0; i
< 4; i
++) {
230 if (optind
>= argc
) {
231 fprintf(stderr
, "No key #%d specified\n", i
);
235 opt
= argv
[optind
++];
236 key
[i
] = strtoull(opt
, &endptr
, 0);
237 if ((*opt
== '\0') || (*endptr
!= '\0')) {
238 fprintf(stderr
, "Invalid key #%d specified: %s\n", i
, opt
);
244 memcpy(&args
[1], key
, sizeof(key
));
246 error
= ps3hvc_dev_hvcall(fd
, PS3HVC_HVCALL_GET_REPO_NODE_VAL
, 5, 2, args
, &result
);
249 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
251 fprintf(stderr
, "hvcall result: 0x%016lx\n", result
);
253 fprintf(stdout
, "0x%016lx 0x%016lx\n", args
[5], args
[6]);
262 static int cmd_panic(int fd
, struct opts
*opts
, int argc
, char **argv
)
270 if (optind
>= argc
) {
271 fprintf(stderr
, "No ARG1 specified\n");
275 arg1
= strtoull(argv
[optind
], &endptr
, 0);
276 if (*endptr
!= '\0') {
277 fprintf(stderr
, "Invalid ARG1 specified: %s\n", argv
[optind
]);
285 error
= ps3hvc_dev_hvcall(fd
, PS3HVC_HVCALL_PANIC
, 1, 0, args
, &result
);
288 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
290 fprintf(stderr
, "hvcall result: 0x%016lx\n", result
);
298 int main(int argc
, char **argv
)
301 int fd
= 0, error
= 0;
303 memset(&opts
, 0, sizeof(opts
));
305 if (process_opts(argc
, argv
, &opts
)) {
314 } else if (opts
.do_version
) {
319 fd
= ps3hvc_dev_open(opts
.device_name
);
321 fprintf(stderr
, "%s: %s\n", opts
.device_name
, strerror(errno
));
326 if (!strcmp(opts
.cmd
, "undocumented_function_8")) {
327 error
= cmd_undocumented_function_8(fd
, &opts
, argc
, argv
);
328 } else if (!strcmp(opts
.cmd
, "construct_event_receive_port")) {
329 error
= cmd_construct_event_receive_port(fd
, &opts
, argc
, argv
);
330 } else if (!strcmp(opts
.cmd
, "destruct_event_receive_port")) {
331 error
= cmd_destruct_event_receive_port(fd
, &opts
, argc
, argv
);
332 } else if (!strcmp(opts
.cmd
, "get_repo_node_val")) {
333 error
= cmd_get_repo_node_val(fd
, &opts
, argc
, argv
);
334 } else if (!strcmp(opts
.cmd
, "panic")) {
335 error
= cmd_panic(fd
, &opts
, argc
, argv
);
348 ps3hvc_dev_close(fd
);