2013-04-22 22:59:25 +04:00
|
|
|
/*
|
|
|
|
* SCLP ASCII access driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Alexander Graf <agraf@suse.de>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or (at
|
|
|
|
* your option) any later version. See the COPYING file in the top-level
|
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
|
2017-07-12 15:49:43 +03:00
|
|
|
#include "libc.h"
|
2013-04-22 22:59:25 +04:00
|
|
|
#include "s390-ccw.h"
|
|
|
|
#include "sclp.h"
|
|
|
|
|
2017-07-12 15:49:46 +03:00
|
|
|
long write(int fd, const void *str, size_t len);
|
|
|
|
|
2013-04-22 22:59:25 +04:00
|
|
|
static char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));
|
|
|
|
|
2017-07-12 15:49:44 +03:00
|
|
|
const unsigned char ebc2asc[256] =
|
|
|
|
/* 0123456789abcdef0123456789abcdef */
|
|
|
|
"................................" /* 1F */
|
|
|
|
"................................" /* 3F */
|
|
|
|
" ...........<(+|&.........!$*);." /* 5F first.chr.here.is.real.space */
|
|
|
|
"-/.........,%_>?.........`:#@'=\""/* 7F */
|
|
|
|
".abcdefghi.......jklmnopqr......" /* 9F */
|
|
|
|
"..stuvwxyz......................" /* BF */
|
|
|
|
".ABCDEFGHI.......JKLMNOPQR......" /* DF */
|
|
|
|
"..STUVWXYZ......0123456789......";/* FF */
|
|
|
|
|
2013-04-22 22:59:25 +04:00
|
|
|
/* Perform service call. Return 0 on success, non-zero otherwise. */
|
|
|
|
static int sclp_service_call(unsigned int command, void *sccb)
|
|
|
|
{
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
|
|
|
|
" ipm %0\n"
|
|
|
|
" srl %0,28"
|
|
|
|
: "=&d" (cc) : "d" (command), "a" (__pa(sccb))
|
|
|
|
: "cc", "memory");
|
2015-06-19 16:40:45 +03:00
|
|
|
consume_sclp_int();
|
2013-04-22 22:59:25 +04:00
|
|
|
if (cc == 3)
|
|
|
|
return -EIO;
|
|
|
|
if (cc == 2)
|
|
|
|
return -EBUSY;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-23 18:43:17 +03:00
|
|
|
void sclp_set_write_mask(uint32_t receive_mask, uint32_t send_mask)
|
2013-04-22 22:59:25 +04:00
|
|
|
{
|
2014-05-19 22:05:40 +04:00
|
|
|
WriteEventMask *sccb = (void *)_sccb;
|
2013-04-22 22:59:25 +04:00
|
|
|
|
|
|
|
sccb->h.length = sizeof(WriteEventMask);
|
|
|
|
sccb->mask_length = sizeof(unsigned int);
|
2018-02-23 18:43:17 +03:00
|
|
|
sccb->cp_receive_mask = receive_mask;
|
|
|
|
sccb->cp_send_mask = send_mask;
|
2013-04-22 22:59:25 +04:00
|
|
|
|
|
|
|
sclp_service_call(SCLP_CMD_WRITE_EVENT_MASK, sccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sclp_setup(void)
|
|
|
|
{
|
2018-02-23 18:43:17 +03:00
|
|
|
sclp_set_write_mask(0, SCLP_EVENT_MASK_MSG_ASCII);
|
2013-04-22 22:59:25 +04:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:49:46 +03:00
|
|
|
long write(int fd, const void *str, size_t len)
|
2013-04-22 22:59:25 +04:00
|
|
|
{
|
2014-05-19 22:05:40 +04:00
|
|
|
WriteEventData *sccb = (void *)_sccb;
|
2017-10-27 19:14:53 +03:00
|
|
|
const char *p = str;
|
|
|
|
size_t data_len = 0;
|
|
|
|
size_t i;
|
2013-04-22 22:59:25 +04:00
|
|
|
|
2017-07-12 15:49:46 +03:00
|
|
|
if (fd != 1 && fd != 2) {
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2017-10-27 19:14:53 +03:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if ((data_len + 1) >= SCCB_DATA_LEN) {
|
|
|
|
/* We would overflow the sccb buffer, abort early */
|
|
|
|
len = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p == '\n') {
|
|
|
|
/* Terminal emulators might need \r\n, so generate it */
|
|
|
|
sccb->data[data_len++] = '\r';
|
|
|
|
}
|
|
|
|
|
|
|
|
sccb->data[data_len++] = *p;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sccb->h.length = sizeof(WriteEventData) + data_len;
|
2013-04-22 22:59:25 +04:00
|
|
|
sccb->h.function_code = SCLP_FC_NORMAL_WRITE;
|
2017-10-27 19:14:53 +03:00
|
|
|
sccb->ebh.length = sizeof(EventBufferHeader) + data_len;
|
2013-04-22 22:59:25 +04:00
|
|
|
sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
|
|
|
|
sccb->ebh.flags = 0;
|
|
|
|
|
|
|
|
sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
|
2017-07-12 15:49:46 +03:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sclp_print(const char *str)
|
|
|
|
{
|
2018-02-23 18:43:10 +03:00
|
|
|
write(1, str, strlen(str));
|
2013-04-22 22:59:25 +04:00
|
|
|
}
|
2016-11-30 22:22:07 +03:00
|
|
|
|
|
|
|
void sclp_get_loadparm_ascii(char *loadparm)
|
|
|
|
{
|
|
|
|
|
|
|
|
ReadInfo *sccb = (void *)_sccb;
|
|
|
|
|
|
|
|
memset((char *)_sccb, 0, sizeof(ReadInfo));
|
|
|
|
sccb->h.length = sizeof(ReadInfo);
|
|
|
|
if (!sclp_service_call(SCLP_CMDW_READ_SCP_INFO, sccb)) {
|
2018-05-29 07:40:09 +03:00
|
|
|
ebcdic_to_ascii((char *) sccb->loadparm, loadparm, LOADPARM_LEN);
|
2016-11-30 22:22:07 +03:00
|
|
|
}
|
|
|
|
}
|
2018-02-23 18:43:16 +03:00
|
|
|
|
|
|
|
int sclp_read(char *str, size_t count)
|
|
|
|
{
|
|
|
|
ReadEventData *sccb = (void *)_sccb;
|
|
|
|
char *buf = (char *)(&sccb->ebh) + 7;
|
|
|
|
|
|
|
|
/* If count exceeds max buffer size, then restrict it to the max size */
|
|
|
|
if (count > SCCB_SIZE - 8) {
|
|
|
|
count = SCCB_SIZE - 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
sccb->h.length = SCCB_SIZE;
|
|
|
|
sccb->h.function_code = SCLP_UNCONDITIONAL_READ;
|
|
|
|
|
|
|
|
sclp_service_call(SCLP_CMD_READ_EVENT_DATA, sccb);
|
|
|
|
memcpy(str, buf, count);
|
|
|
|
|
|
|
|
return sccb->ebh.length - 7;
|
|
|
|
}
|