| 1 | /* |
| 2 | * S390 CCW boot loader |
| 3 | * |
| 4 | * Copyright (c) 2013 Alexander Graf <agraf@suse.de> |
| 5 | * |
| 6 | * This work is licensed under the terms of the GNU GPL, version 2 or (at |
| 7 | * your option) any later version. See the COPYING file in the top-level |
| 8 | * directory. |
| 9 | */ |
| 10 | |
| 11 | #ifndef S390_CCW_H |
| 12 | #define S390_CCW_H |
| 13 | |
| 14 | /* #define DEBUG */ |
| 15 | |
| 16 | #include <stdbool.h> |
| 17 | #include <stddef.h> |
| 18 | #include <stdint.h> |
| 19 | #include <stdio.h> |
| 20 | |
| 21 | typedef unsigned char u8; |
| 22 | typedef unsigned short u16; |
| 23 | typedef unsigned int u32; |
| 24 | typedef unsigned long long u64; |
| 25 | |
| 26 | #define true 1 |
| 27 | #define false 0 |
| 28 | #define PAGE_SIZE 4096 |
| 29 | |
| 30 | #define EIO 1 |
| 31 | #define EBUSY 2 |
| 32 | #define ENODEV 3 |
| 33 | #define EINVAL 4 |
| 34 | |
| 35 | #ifndef MIN |
| 36 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
| 37 | #endif |
| 38 | #ifndef MIN_NON_ZERO |
| 39 | #define MIN_NON_ZERO(a, b) ((a) == 0 ? (b) : \ |
| 40 | ((b) == 0 ? (a) : (MIN(a, b)))) |
| 41 | #endif |
| 42 | |
| 43 | /* |
| 44 | * Round number down to multiple. Requires that d be a power of 2. |
| 45 | * Works even if d is a smaller type than n. |
| 46 | */ |
| 47 | #ifndef ROUND_DOWN |
| 48 | #define ROUND_DOWN(n, d) ((n) & -(0 ? (n) : (d))) |
| 49 | #endif |
| 50 | |
| 51 | /* |
| 52 | * Round number up to multiple. Requires that d be a power of 2. |
| 53 | * Works even if d is a smaller type than n. |
| 54 | */ |
| 55 | #ifndef ROUND_UP |
| 56 | #define ROUND_UP(n, d) ROUND_DOWN((n) + (d) - 1, (d)) |
| 57 | #endif |
| 58 | |
| 59 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 60 | |
| 61 | #include "cio.h" |
| 62 | #include "iplb.h" |
| 63 | |
| 64 | /* start.s */ |
| 65 | void disabled_wait(void) __attribute__ ((__noreturn__)); |
| 66 | void consume_sclp_int(void); |
| 67 | void consume_io_int(void); |
| 68 | |
| 69 | /* main.c */ |
| 70 | void write_subsystem_identification(void); |
| 71 | void write_iplb_location(void); |
| 72 | unsigned int get_loadparm_index(void); |
| 73 | void main(void); |
| 74 | |
| 75 | /* netmain.c */ |
| 76 | int netmain(void); |
| 77 | |
| 78 | /* sclp.c */ |
| 79 | void sclp_print(const char *string); |
| 80 | void sclp_set_write_mask(uint32_t receive_mask, uint32_t send_mask); |
| 81 | void sclp_setup(void); |
| 82 | void sclp_get_loadparm_ascii(char *loadparm); |
| 83 | bool sclp_is_diag320_on(void); |
| 84 | bool sclp_is_fac_ipl_flag_on(uint16_t fac_ipl_flag); |
| 85 | int sclp_read(char *str, size_t count); |
| 86 | |
| 87 | /* bootmap.c */ |
| 88 | void zipl_load(void); |
| 89 | |
| 90 | typedef enum ZiplBootMode { |
| 91 | ZIPL_BOOT_MODE_NORMAL = 0, |
| 92 | ZIPL_BOOT_MODE_SECURE_AUDIT = 1, |
| 93 | ZIPL_BOOT_MODE_SECURE = 2, |
| 94 | } ZiplBootMode; |
| 95 | |
| 96 | extern ZiplBootMode boot_mode; |
| 97 | ZiplBootMode get_boot_mode(uint8_t hdr_flags); |
| 98 | |
| 99 | /* jump2ipl.c */ |
| 100 | void write_reset_psw(uint64_t psw); |
| 101 | int jump_to_IPL_code(uint64_t address); |
| 102 | void jump_to_low_kernel(void); |
| 103 | |
| 104 | /* menu.c */ |
| 105 | void menu_set_parms(uint8_t boot_menu_flag, uint32_t boot_menu_timeout); |
| 106 | int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end); |
| 107 | bool menu_is_enabled_zipl(void); |
| 108 | int menu_get_enum_boot_index(bool *valid_entries); |
| 109 | bool menu_is_enabled_enum(void); |
| 110 | int menu_get_boot_index(bool *valid_entries); |
| 111 | |
| 112 | __attribute__ ((__noreturn__)) |
| 113 | static inline void panic(const char *string) |
| 114 | { |
| 115 | printf("ERROR: %s\n ", string); |
| 116 | disabled_wait(); |
| 117 | } |
| 118 | |
| 119 | static inline void fill_hex(char *out, unsigned char val) |
| 120 | { |
| 121 | const char hex[] = "0123456789abcdef"; |
| 122 | |
| 123 | out[0] = hex[(val >> 4) & 0xf]; |
| 124 | out[1] = hex[val & 0xf]; |
| 125 | } |
| 126 | |
| 127 | static inline void fill_hex_val(char *out, void *ptr, unsigned size) |
| 128 | { |
| 129 | unsigned char *value = ptr; |
| 130 | unsigned int i; |
| 131 | |
| 132 | for (i = 0; i < size; i++) { |
| 133 | fill_hex(&out[i*2], value[i]); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | static inline void debug_print_int(const char *desc, u64 addr) |
| 138 | { |
| 139 | #ifdef DEBUG |
| 140 | printf("%s 0x%llx\n", desc, addr); |
| 141 | #endif |
| 142 | } |
| 143 | |
| 144 | static inline void debug_print_addr(const char *desc, void *p) |
| 145 | { |
| 146 | #ifdef DEBUG |
| 147 | debug_print_int(desc, (unsigned int)(unsigned long)p); |
| 148 | #endif |
| 149 | } |
| 150 | |
| 151 | /*********************************************** |
| 152 | * Hypercall functions * |
| 153 | ***********************************************/ |
| 154 | |
| 155 | #define KVM_S390_VIRTIO_NOTIFY 0 |
| 156 | #define KVM_S390_VIRTIO_RESET 1 |
| 157 | #define KVM_S390_VIRTIO_SET_STATUS 2 |
| 158 | #define KVM_S390_VIRTIO_CCW_NOTIFY 3 |
| 159 | |
| 160 | #define MAX_SECTOR_SIZE 4096 |
| 161 | |
| 162 | static inline void IPL_assert(bool term, const char *message) |
| 163 | { |
| 164 | if (!term) { |
| 165 | panic(message); /* no return */ |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | static inline void IPL_check(bool term, const char *message) |
| 170 | { |
| 171 | if (!term) { |
| 172 | printf("WARNING: %s\n", message); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | extern const unsigned char ebc2asc[256]; |
| 177 | static inline void ebcdic_to_ascii(const char *src, |
| 178 | char *dst, |
| 179 | unsigned int size) |
| 180 | { |
| 181 | unsigned int i; |
| 182 | |
| 183 | for (i = 0; i < size; i++) { |
| 184 | unsigned c = src[i]; |
| 185 | dst[i] = ebc2asc[c]; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | #endif /* S390_CCW_H */ |