Re: [kvm-unit-tests PATCH v3 08/13] s390x: Add linemode console

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2018-12-18 10:26, Janosch Frank wrote:
> z/VM isn't fond of vt220, so we need line mode when running under z/VM.
> 
> Signed-off-by: Janosch Frank <frankja@xxxxxxxxxxxxx>
> ---
>  lib/s390x/sclp-console.c | 195 ++++++++++++++++++++++++++++++++++++++++++-----
>  lib/s390x/sclp.h         |  67 ++++++++++++++++
>  2 files changed, 243 insertions(+), 19 deletions(-)
[...]
> +
> +static bool initialized;
> +
> +static void sclp_print_ascii(const char *str)
> +{
> +	int len = strlen(str);
> +	WriteEventData *sccb = (void *)_sccb;
> +
> +	sclp_wait_busy();
> +	sclp_busy = true;

What happened to sclp_mark_busy() ?

> +	memset(sccb, 0, sizeof(*sccb));
> +	sccb->h.length = sizeof(WriteEventData) + len;
> +	sccb->h.function_code = SCLP_FC_NORMAL_WRITE;
> +	sccb->ebh.length = sizeof(EventBufferHeader) + len;
> +	sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
> +	memcpy(sccb->data, str, len);
> +
> +	sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
> +	sclp_wait_busy();

Hmm, if the functions do a sclp_wait_busy() at the beginning already, do
we still need it at the end of the functions, too?

... I've got the feeling that we need some clearer conventions here.
Could you maybe add some comments to the source code?

> +}
> +
> +static void sclp_print_lm(const char *str)
> +{
> +	unsigned char *ptr, *end, ch;
> +	unsigned int count, offset, len;
> +	struct write_sccb *sccb;
> +	struct msg_buf *msg;
> +	struct mdb *mdb;
> +	struct mto *mto;
> +	struct go *go;
> +
> +	sclp_wait_busy();
> +	sclp_busy = true;

sclp_mark_busy() ?

> +	sccb = (struct write_sccb *) _sccb;
> +	end = (unsigned char *) sccb + 4096 - 1;
> +	memset(sccb, 0, sizeof(*sccb));
> +	ptr = (unsigned char *) &sccb->msg.mdb.mto;
> +	len = strlen(str);
> +	offset = 0;
> +	do {
> +		for (count = sizeof(*mto); offset < len; count++) {
> +			ch = str[offset++];
> +			if ((ch == 0x0a) || (ptr + count > end))
> +				break;
> +			ptr[count] = _ascebc[ch];
> +		}
> +		mto = (struct mto *) ptr;
> +		memset(mto, 0, sizeof(*mto));
> +		mto->length = count;
> +		mto->type = 4;
> +		mto->line_type_flags = LNTPFLGS_ENDTEXT;
> +		ptr += count;
> +	} while ((offset < len) && (ptr + sizeof(*mto) <= end));

	} while (offset < len && ptr + sizeof(*mto) <= end);

> +	len = ptr - (unsigned char *) sccb;
> +	sccb->header.length = len - offsetof(struct write_sccb, header);
> +	msg = &sccb->msg;
> +	msg->header.type = EVTYP_MSG;
> +	msg->header.length = len - offsetof(struct write_sccb, msg.header);
> +	mdb = &msg->mdb;
> +	mdb->header.type = 1;
> +	mdb->header.tag = 0xD4C4C240;
> +	mdb->header.revision_code = 1;
> +	mdb->header.length = len - offsetof(struct write_sccb, msg.mdb.header);
> +	go = &mdb->go;
> +	go->length = sizeof(*go);
> +	go->type = 1;
> +	sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
> +	sclp_wait_busy();
> +}
> +
> +/*
> + * SCLP needs to be initialized by setting a send and receive mask,
> + * indicating which messages the control program (we) want(s) to
> + * send/receive.
> + */
> +static bool sclp_set_write_mask(void)
>  {
>  	WriteEventMask *sccb = (void *)_sccb;
>  
>  	sclp_mark_busy();
> +	memset(_sccb, 0, sizeof(*sccb));
>  	sccb->h.length = sizeof(WriteEventMask);
> -	sccb->mask_length = sizeof(unsigned int);
> -	sccb->receive_mask = SCLP_EVENT_MASK_MSG_ASCII;
> -	sccb->cp_receive_mask = SCLP_EVENT_MASK_MSG_ASCII;
> -	sccb->send_mask = SCLP_EVENT_MASK_MSG_ASCII;
> -	sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII;
> +	sccb->h.function_code = 0;
> +	sccb->mask_length = sizeof(sccb_mask_t);
> +
> +	/* For now we don't process sclp input. */
> +	sccb->cp_receive_mask = 0;
> +	/* We send ASCII and line mode. */
> +	sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII | SCLP_EVENT_MASK_MSG;
>  
>  	sclp_service_call(SCLP_CMD_WRITE_EVENT_MASK, sccb);
> +	sclp_wait_busy();
> +	if (sccb->h.response_code != SCLP_RC_NORMAL_COMPLETION)
> +		return false;
> +	else {
> +		initialized = true;
> +		return true;
> +	}

Maybe rather assert(sccb->h.response_code == SCLP_RC_NORMAL_COMPLETION) ?
It does not make much sense to continue otherwise, does it?

 Thomas



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux