Subject: Re: inb, outb, i386_set_ioperm and such
To: Bruce J.A. Nourish <netbsd@bjan.freeshell.org>
From: Jachym Holecek <freza@psi.cz>
List: tech-userlevel
Date: 03/28/2004 19:33:05
Hello,

> * Given "from" and "num", two integers that describe a range of ports
>   to open up for inb/outb access, does the following code set up the
>   iomap correctly?
> 
>   for (i = 0; i < num; ++i)
>        iomap[(from + num) / 32] |= 1 << (from + num) % 32;
> 
>   return (i386_set_ioperm(iomap) ? ERR_ROOT : 0);

Yes, except you may be discarding privileges you already had (depending
on where does iomap[] come from). FWIW here's what I used to have a
Linux JTAG program working:

int
ioperm(unsigned long from, unsigned long num, int permit)
{
        unsigned long   ports[32];
        unsigned long   i;

        if (i386_get_ioperm(ports) == -1)
                return -1;

        for (i = from; i < (from + num); i++)
                if (permit)
                        ports[i / 32] &= ~(1 << (i % 32));
                else
                        ports[i / 32] |= (1 << (i % 32));

        if (i386_set_ioperm(ports) == -1)
                return -1;

        return 0;
}

	Regards,
		-- Jachym