view arch/io.c @ 16:3d69c66b2610

arch: last fixup, now things seem to work as expected
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Fri, 08 Apr 2011 09:44:57 -0400
parents c75be274ce23
children f219716c6b54
line wrap: on
line source

#include "channel.h"
#include <die.h>

u32 find_dev(int devnum)
{
	struct schib schib;
	u32 sch;

	for(sch=0x10000; sch<=0x1ffff; sch++) {
		if (store_sch(sch, &schib))
			continue;

		if (!schib.pmcw.v)
			continue;

		if (schib.pmcw.dev_num != devnum)
			continue;

		if (!schib.pmcw.e) {
			schib.pmcw.e = 1;

			if (modify_sch(sch, &schib))
				continue;
		}

		return sch;
	}

	return 0;
}

extern void IOINT(void);

void init_io_int()
{
	struct psw psw;

	// set up the IO interrupt handler
	psw.ea  = 1;
	psw.ba  = 1;
	psw.ptr = (u64) &IOINT;

	__builtin_memcpy(((void*) 0x1f0), &psw, sizeof(struct psw));
}

void wait_for_io_int()
{
	struct psw psw;

        __builtin_memset(&psw, 0, sizeof(struct psw));
        psw.io  = 1;
        psw.ea  = 1;
        psw.ba  = 1;
	psw.w   = 1;

        asm volatile(
                "       larl    %%r1,0f\n"
                "       stg     %%r1,%0\n"
                "       lpswe   %1\n"
                "0:\n"
        : /* output */
          "=m" (psw.ptr)
        : /* input */
          "m" (psw)
        : /* clobbered */
          "r1", "r2"
        );

	if (*((u8*) 0x210) & 0x04)
		return;

	die();
}