Skip to content

Commit 30c2df5

Browse files
author
Martin Schwidefsky
committed
[S390] sclp: event buffer dissection
Move gds vector/subvector find functions to the sclp header file. Simplify event buffer dissection in sclp tty code. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent fca894e commit 30c2df5

2 files changed

Lines changed: 60 additions & 84 deletions

File tree

‎drivers/s390/char/sclp.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,26 @@ sclp_ascebc_str(unsigned char *str, int nr)
186186
(MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr);
187187
}
188188

189+
static inline struct gds_vector *
190+
sclp_find_gds_vector(void *start, void *end, u16 id)
191+
{
192+
struct gds_vector *v;
193+
194+
for (v = start; (void *) v < end; v = (void *) v + v->length)
195+
if (v->gds_id == id)
196+
return v;
197+
return NULL;
198+
}
199+
200+
static inline struct gds_subvector *
201+
sclp_find_gds_subvector(void *start, void *end, u8 key)
202+
{
203+
struct gds_subvector *sv;
204+
205+
for (sv = start; (void *) sv < end; sv = (void *) sv + sv->length)
206+
if (sv->key == key)
207+
return sv;
208+
return NULL;
209+
}
210+
189211
#endif /* __SCLP_H__ */

‎drivers/s390/char/sclp_tty.c‎

Lines changed: 38 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -408,118 +408,72 @@ static int sclp_switch_cases(unsigned char *buf, int count)
408408
return op - buf;
409409
}
410410

411-
static void
412-
sclp_get_input(unsigned char *start, unsigned char *end)
411+
static void sclp_get_input(struct gds_subvector *sv)
413412
{
413+
unsigned char *str;
414414
int count;
415415

416-
count = end - start;
416+
str = (unsigned char *) (sv + 1);
417+
count = sv->length - sizeof(*sv);
417418
if (sclp_tty_tolower)
418-
EBC_TOLOWER(start, count);
419-
count = sclp_switch_cases(start, count);
419+
EBC_TOLOWER(str, count);
420+
count = sclp_switch_cases(str, count);
420421
/* convert EBCDIC to ASCII (modify original input in SCCB) */
421-
sclp_ebcasc_str(start, count);
422+
sclp_ebcasc_str(str, count);
422423

423424
/* transfer input to high level driver */
424-
sclp_tty_input(start, count);
425-
}
426-
427-
static inline struct gds_vector *
428-
find_gds_vector(struct gds_vector *start, struct gds_vector *end, u16 id)
429-
{
430-
struct gds_vector *vec;
431-
432-
for (vec = start; vec < end; vec = (void *) vec + vec->length)
433-
if (vec->gds_id == id)
434-
return vec;
435-
return NULL;
425+
sclp_tty_input(str, count);
436426
}
437427

438-
static inline struct gds_subvector *
439-
find_gds_subvector(struct gds_subvector *start,
440-
struct gds_subvector *end, u8 key)
428+
static inline void sclp_eval_selfdeftextmsg(struct gds_subvector *sv)
441429
{
442-
struct gds_subvector *subvec;
430+
void *end;
443431

444-
for (subvec = start; subvec < end;
445-
subvec = (void *) subvec + subvec->length)
446-
if (subvec->key == key)
447-
return subvec;
448-
return NULL;
432+
end = (void *) sv + sv->length;
433+
for (sv = sv + 1; (void *) sv < end; sv = (void *) sv + sv->length)
434+
if (sv->key == 0x30)
435+
sclp_get_input(sv);
449436
}
450437

451-
static inline void
452-
sclp_eval_selfdeftextmsg(struct gds_subvector *start,
453-
struct gds_subvector *end)
438+
static inline void sclp_eval_textcmd(struct gds_vector *v)
454439
{
455-
struct gds_subvector *subvec;
456-
457-
subvec = start;
458-
while (subvec < end) {
459-
subvec = find_gds_subvector(subvec, end, 0x30);
460-
if (!subvec)
461-
break;
462-
sclp_get_input((unsigned char *)(subvec + 1),
463-
(unsigned char *) subvec + subvec->length);
464-
subvec = (void *) subvec + subvec->length;
465-
}
466-
}
440+
struct gds_subvector *sv;
441+
void *end;
467442

468-
static inline void
469-
sclp_eval_textcmd(struct gds_subvector *start,
470-
struct gds_subvector *end)
471-
{
472-
struct gds_subvector *subvec;
443+
end = (void *) v + v->length;
444+
for (sv = (struct gds_subvector *) (v + 1);
445+
(void *) sv < end; sv = (void *) sv + sv->length)
446+
if (sv->key == GDS_KEY_SELFDEFTEXTMSG)
447+
sclp_eval_selfdeftextmsg(sv);
473448

474-
subvec = start;
475-
while (subvec < end) {
476-
subvec = find_gds_subvector(subvec, end,
477-
GDS_KEY_SELFDEFTEXTMSG);
478-
if (!subvec)
479-
break;
480-
sclp_eval_selfdeftextmsg((struct gds_subvector *)(subvec + 1),
481-
(void *)subvec + subvec->length);
482-
subvec = (void *) subvec + subvec->length;
483-
}
484449
}
485450

486-
static inline void
487-
sclp_eval_cpmsu(struct gds_vector *start, struct gds_vector *end)
451+
static inline void sclp_eval_cpmsu(struct gds_vector *v)
488452
{
489-
struct gds_vector *vec;
453+
void *end;
490454

491-
vec = start;
492-
while (vec < end) {
493-
vec = find_gds_vector(vec, end, GDS_ID_TEXTCMD);
494-
if (!vec)
495-
break;
496-
sclp_eval_textcmd((struct gds_subvector *)(vec + 1),
497-
(void *) vec + vec->length);
498-
vec = (void *) vec + vec->length;
499-
}
455+
end = (void *) v + v->length;
456+
for (v = v + 1; (void *) v < end; v = (void *) v + v->length)
457+
if (v->gds_id == GDS_ID_TEXTCMD)
458+
sclp_eval_textcmd(v);
500459
}
501460

502461

503-
static inline void
504-
sclp_eval_mdsmu(struct gds_vector *start, void *end)
462+
static inline void sclp_eval_mdsmu(struct gds_vector *v)
505463
{
506-
struct gds_vector *vec;
507-
508-
vec = find_gds_vector(start, end, GDS_ID_CPMSU);
509-
if (vec)
510-
sclp_eval_cpmsu(vec + 1, (void *) vec + vec->length);
464+
v = sclp_find_gds_vector(v + 1, (void *) v + v->length, GDS_ID_CPMSU);
465+
if (v)
466+
sclp_eval_cpmsu(v);
511467
}
512468

513-
static void
514-
sclp_tty_receiver(struct evbuf_header *evbuf)
469+
static void sclp_tty_receiver(struct evbuf_header *evbuf)
515470
{
516-
struct gds_vector *start, *end, *vec;
471+
struct gds_vector *v;
517472

518-
start = (struct gds_vector *)(evbuf + 1);
519-
end = (void *) evbuf + evbuf->length;
520-
vec = find_gds_vector(start, end, GDS_ID_MDSMU);
521-
if (vec)
522-
sclp_eval_mdsmu(vec + 1, (void *) vec + vec->length);
473+
v = sclp_find_gds_vector(evbuf + 1, (void *) evbuf + evbuf->length,
474+
GDS_ID_MDSMU);
475+
if (v)
476+
sclp_eval_mdsmu(v);
523477
}
524478

525479
static void

0 commit comments

Comments
 (0)