|
Revision 5962, 1.4 KB
(checked in by khali, 10 months ago)
|
|
isaset: Add support for word (16-bit) and long (32-bit) writes
Sometimes the hardware expects 16-bit or 32-bit writes rather than byte
writes. Add support to isaset so that the user can ask for such writes.
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | util.c - helper functions |
|---|
| 3 | Copyright (C) 2006 Jean Delvare <khali@linux-fr.org> |
|---|
| 4 | |
|---|
| 5 | This program is free software; you can redistribute it and/or modify |
|---|
| 6 | it under the terms of the GNU General Public License as published by |
|---|
| 7 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | (at your option) any later version. |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | #include <stdio.h> |
|---|
| 12 | #include "util.h" |
|---|
| 13 | |
|---|
| 14 | /* To keep glibc2 happy */ |
|---|
| 15 | #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ >= 0 |
|---|
| 16 | #include <sys/io.h> |
|---|
| 17 | #else |
|---|
| 18 | #include <asm/io.h> |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | /* Return 1 if we should continue, 0 if we should abort */ |
|---|
| 22 | int user_ack(int def) |
|---|
| 23 | { |
|---|
| 24 | char s[2]; |
|---|
| 25 | int ret; |
|---|
| 26 | |
|---|
| 27 | if (!fgets(s, 2, stdin)) |
|---|
| 28 | return 0; /* Nack by default */ |
|---|
| 29 | |
|---|
| 30 | switch (s[0]) { |
|---|
| 31 | case 'y': |
|---|
| 32 | case 'Y': |
|---|
| 33 | ret = 1; |
|---|
| 34 | break; |
|---|
| 35 | case 'n': |
|---|
| 36 | case 'N': |
|---|
| 37 | ret = 0; |
|---|
| 38 | break; |
|---|
| 39 | default: |
|---|
| 40 | ret = def; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | /* Flush extra characters */ |
|---|
| 44 | while (s[0] != '\n') { |
|---|
| 45 | int c = fgetc(stdin); |
|---|
| 46 | if (c == EOF) { |
|---|
| 47 | ret = 0; |
|---|
| 48 | break; |
|---|
| 49 | } |
|---|
| 50 | s[0] = c; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | return ret; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | /* I/O read of specified size */ |
|---|
| 57 | unsigned long inx(int addr, int width) |
|---|
| 58 | { |
|---|
| 59 | switch (width) { |
|---|
| 60 | case 2: |
|---|
| 61 | return inw(addr); |
|---|
| 62 | break; |
|---|
| 63 | case 4: |
|---|
| 64 | return inl(addr); |
|---|
| 65 | break; |
|---|
| 66 | default: |
|---|
| 67 | return inb(addr); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | /* I/O write of specified size */ |
|---|
| 72 | void outx(unsigned long value, int addr, int width) |
|---|
| 73 | { |
|---|
| 74 | switch (width) { |
|---|
| 75 | case 2: |
|---|
| 76 | outw(value, addr); |
|---|
| 77 | break; |
|---|
| 78 | case 4: |
|---|
| 79 | outl(value, addr); |
|---|
| 80 | break; |
|---|
| 81 | default: |
|---|
| 82 | outb(value, addr); |
|---|
| 83 | } |
|---|
| 84 | } |
|---|