cca24d06d8
kernel (sys task). The main reason is that these would have to become cpu local variables on SMP. Once the system task is not a task but a genuine part of the kernel there is even less reason to have these extra variables as proc_ptr will already contain all neccessary information. In addition converting who_e to the process pointer and back again all the time will be avoided. Although proc_ptr will contain all important information, accessing it as a cpu local variable will be fairly expensive, hence the value would be assigned to some on stack local variable. Therefore it is better to add the 'caller' argument to the syscall handlers to pass the value on stack anyway. It also clearly denotes on who's behalf is the syscall being executed. This patch also ANSIfies the syscall function headers. Last but not least, it also fixes a potential bug in virtual_copy_f() in case the check is disabled. So far the function in case of a failure could possible reuse an old who_p in case this function had not been called from the system task. virtual_copy_f() takes the caller as a parameter too. In case the checking is disabled, the caller must be NULL and non NULL if it is enabled as we must be able to suspend the caller.
90 lines
2.4 KiB
C
90 lines
2.4 KiB
C
/* The kernel call implemented in this file:
|
|
* m_type: SYS_DEVIO
|
|
*
|
|
* The parameters for this kernel call are:
|
|
* m2_i3: DIO_REQUEST (request input or output)
|
|
* m2_l1: DIO_PORT (port to read/ write)
|
|
* m2_l2: DIO_VALUE (value to write/ return value read)
|
|
*/
|
|
|
|
#include "../system.h"
|
|
#include <minix/devio.h>
|
|
#include <minix/endpoint.h>
|
|
#include <minix/portio.h>
|
|
|
|
#if USE_DEVIO
|
|
|
|
/*===========================================================================*
|
|
* do_devio *
|
|
*===========================================================================*/
|
|
PUBLIC int do_devio(struct proc * caller, message * m_ptr)
|
|
{
|
|
struct priv *privp;
|
|
port_t port;
|
|
struct io_range *iorp;
|
|
int i, size, nr_io_range;
|
|
int io_type, io_dir;
|
|
|
|
io_type = m_ptr->DIO_REQUEST & _DIO_TYPEMASK;
|
|
io_dir = m_ptr->DIO_REQUEST & _DIO_DIRMASK;
|
|
|
|
switch (io_type)
|
|
{
|
|
case _DIO_BYTE: size= 1; break;
|
|
case _DIO_WORD: size= 2; break;
|
|
case _DIO_LONG: size= 4; break;
|
|
default: size= 4; break; /* Be conservative */
|
|
}
|
|
|
|
privp= priv(caller);
|
|
if (!privp)
|
|
{
|
|
kprintf("no priv structure!\n");
|
|
goto doit;
|
|
}
|
|
if (privp->s_flags & CHECK_IO_PORT)
|
|
{
|
|
port= m_ptr->DIO_PORT;
|
|
nr_io_range= privp->s_nr_io_range;
|
|
for (i= 0, iorp= privp->s_io_tab; i<nr_io_range; i++, iorp++)
|
|
{
|
|
if (port >= iorp->ior_base && port+size-1 <= iorp->ior_limit)
|
|
break;
|
|
}
|
|
if (i >= nr_io_range)
|
|
{
|
|
kprintf("do_devio: port 0x%x (size %d) not allowed\n",
|
|
m_ptr->DIO_PORT, size);
|
|
return EPERM;
|
|
}
|
|
}
|
|
|
|
doit:
|
|
if (m_ptr->DIO_PORT & (size-1))
|
|
{
|
|
kprintf("do_devio: unaligned port 0x%x (size %d)\n",
|
|
m_ptr->DIO_PORT, size);
|
|
return EPERM;
|
|
}
|
|
|
|
/* Process a single I/O request for byte, word, and long values. */
|
|
if (io_dir == _DIO_INPUT) {
|
|
switch (io_type) {
|
|
/* maybe "it" should not be called ports */
|
|
case _DIO_BYTE: m_ptr->DIO_VALUE = inb(m_ptr->DIO_PORT); break;
|
|
case _DIO_WORD: m_ptr->DIO_VALUE = inw(m_ptr->DIO_PORT); break;
|
|
case _DIO_LONG: m_ptr->DIO_VALUE = inl(m_ptr->DIO_PORT); break;
|
|
default: return(EINVAL);
|
|
}
|
|
} else {
|
|
switch (io_type) {
|
|
case _DIO_BYTE: outb(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
|
case _DIO_WORD: outw(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
|
case _DIO_LONG: outl(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
|
default: return(EINVAL);
|
|
}
|
|
}
|
|
return(OK);
|
|
}
|
|
|
|
#endif /* USE_DEVIO */
|