xref: /kvm-unit-tests/lib/s390x/io.c (revision 95a9408860fc8dacb73e9b302fb96536f91d5ccf)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * s390x io implementation
4  *
5  * Copyright (c) 2017 Red Hat Inc
6  *
7  * Authors:
8  *  Thomas Huth <thuth@redhat.com>
9  *  David Hildenbrand <david@redhat.com>
10  */
11 #include <libcflat.h>
12 #include <argv.h>
13 #include <vmalloc.h>
14 #include <asm/spinlock.h>
15 #include <asm/facility.h>
16 #include <asm/sigp.h>
17 #include "sclp.h"
18 #include "uv.h"
19 #include "smp.h"
20 
21 extern char ipl_args[];
22 uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
23 
24 static struct spinlock lock;
25 
26 void setup(void);
27 
puts(const char * s)28 void puts(const char *s)
29 {
30 	spin_lock(&lock);
31 	sclp_print(s);
32 	spin_unlock(&lock);
33 }
34 
setup(void)35 void setup(void)
36 {
37 	struct cpu this_cpu_tmp = { 0 };
38 
39 	/*
40 	 * Set a temporary empty struct cpu for the boot CPU, needed for
41 	 * correct interrupt handling in the setup process.
42 	 * smp_setup will allocate and set the permanent one.
43 	 */
44 	THIS_CPU = &this_cpu_tmp;
45 
46 	setup_args_progname(ipl_args);
47 	setup_facilities();
48 	sclp_read_info();
49 	sclp_facilities_setup();
50 	sclp_console_setup();
51 	sclp_memory_setup();
52 	uv_setup();
53 	smp_setup();
54 }
55 
exit(int code)56 void exit(int code)
57 {
58 	smp_teardown();
59 	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
60 	while (1) {
61 		sigp(stap(), SIGP_STOP, 0, NULL);
62 	}
63 }
64