Skip to content

Commit

Permalink
x86: ioport_{32|64}.c unification
Browse files Browse the repository at this point in the history
ioport_{32|64}.c unification.

This patch unifies the code from the ioport_32.c and ioport_64.c files.

Tested and working fine with i386 and x86_64 kernels.

Signed-off-by: Miguel Botón <mboton@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
mboton@gmail.com authored and Ingo Molnar committed Jan 30, 2008
1 parent aaf2304 commit ccafa59
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 126 deletions.
2 changes: 1 addition & 1 deletion arch/x86/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CFLAGS_vsyscall_64.o := $(PROFILING) -g0

obj-y := process_$(BITS).o signal_$(BITS).o entry_$(BITS).o
obj-y += traps_$(BITS).o irq_$(BITS).o
obj-y += time_$(BITS).o ioport_$(BITS).o ldt.o
obj-y += time_$(BITS).o ioport.o ldt.o
obj-y += setup_$(BITS).o i8259_$(BITS).o
obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
Expand Down
37 changes: 29 additions & 8 deletions arch/x86/kernel/ioport_32.c → arch/x86/kernel/ioport.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This contains the io-permission bitmap code - written by obz, with changes
* by Linus.
* by Linus. 32/64 bits code unification by Miguel Botón.
*/

#include <linux/sched.h>
Expand Down Expand Up @@ -36,7 +36,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
struct thread_struct * t = &current->thread;
struct tss_struct * tss;
unsigned long i, max_long;
unsigned int i, max_long, bytes, bytes_updated;

if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
return -EINVAL;
Expand Down Expand Up @@ -79,8 +79,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
if (t->io_bitmap_ptr[i] != ~0UL)
max_long = i;

t->io_bitmap_max = (max_long + 1) * sizeof(unsigned long);
bytes = (max_long + 1) * sizeof(unsigned long);
bytes_updated = max(bytes, t->io_bitmap_max);

t->io_bitmap_max = bytes;

#ifdef CONFIG_X86_32
/*
* Sets the lazy trigger so that the next I/O operation will
* reload the correct bitmap.
Expand All @@ -89,6 +93,10 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
*/
tss->x86_tss.io_bitmap_base = INVALID_IO_BITMAP_OFFSET_LAZY;
tss->io_bitmap_owner = NULL;
#else
/* Update the TSS: */
memcpy(tss->io_bitmap, t->io_bitmap_ptr, bytes_updated);
#endif

put_cpu();

Expand All @@ -105,13 +113,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
* on system-call entry - see also fork() and the signal handling
* code.
*/

#ifdef CONFIG_X86_32
asmlinkage long sys_iopl(unsigned long regsp)
{
volatile struct pt_regs *regs = (struct pt_regs *)&regsp;
unsigned int level = regs->bx;
unsigned int old = (regs->flags >> 12) & 3;
struct thread_struct *t = &current->thread;

if (level > 3)
return -EINVAL;
Expand All @@ -120,10 +127,24 @@ asmlinkage long sys_iopl(unsigned long regsp)
if (!capable(CAP_SYS_RAWIO))
return -EPERM;
}
regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);

return 0;
}
#else
asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs)
{
unsigned int old = (regs->flags >> 12) & 3;

t->iopl = level << 12;
regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | t->iopl;
set_iopl_mask(t->iopl);
if (level > 3)
return -EINVAL;
/* Trying to gain more privileges? */
if (level > old) {
if (!capable(CAP_SYS_RAWIO))
return -EPERM;
}
regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);

return 0;
}
#endif
117 changes: 0 additions & 117 deletions arch/x86/kernel/ioport_64.c

This file was deleted.

0 comments on commit ccafa59

Please sign in to comment.