|
|
1.1 ! root 1: /* ! 2: * Linux I/O port management. ! 3: * Copyright (C) 1995 Shantanu Goel. ! 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, or (at your option) ! 8: * any later version. ! 9: * ! 10: * This program is distributed in the hope that it will be useful, ! 11: * but WITHOUT ANY WARRANTY; without even the implied warranty of ! 12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! 13: * GNU General Public License for more details. ! 14: * ! 15: * You should have received a copy of the GNU General Public License ! 16: * along with this program; if not, write to the Free Software ! 17: * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. ! 18: */ ! 19: ! 20: #include <linux/ioport.h> ! 21: ! 22: #define NPORTS 65536 ! 23: #define BITS_PER_WORD 32 ! 24: #define NWORDS (NPORTS / BITS_PER_WORD) ! 25: ! 26: /* ! 27: * This bitmap keeps track of all allocated ports. ! 28: * A bit is set if the port has been allocated. ! 29: */ ! 30: static unsigned port_bitmap[NWORDS]; ! 31: ! 32: void snarf_region(unsigned, unsigned); ! 33: ! 34: /* ! 35: * Check if a region is available for use. ! 36: */ ! 37: int ! 38: check_region(unsigned port, unsigned size) ! 39: { ! 40: unsigned i; ! 41: ! 42: for (i = port; i < port + size; i++) ! 43: if (port_bitmap[i/BITS_PER_WORD] & (1 << (i%BITS_PER_WORD))) ! 44: return (1); ! 45: return (0); ! 46: } ! 47: ! 48: /* ! 49: * Allocate a region. ! 50: */ ! 51: void ! 52: request_region(unsigned port, unsigned size, const char *name) ! 53: { ! 54: unsigned i; ! 55: ! 56: for (i = port; i < port + size; i++) ! 57: port_bitmap[i / BITS_PER_WORD] |= 1 << (i % BITS_PER_WORD); ! 58: } ! 59: ! 60: /* ! 61: * For compatibility with older kernels. ! 62: */ ! 63: void ! 64: snarf_region(unsigned port, unsigned size) ! 65: { ! 66: request_region(port, size, 0); ! 67: } ! 68: ! 69: /* ! 70: * Deallocate a region. ! 71: */ ! 72: void ! 73: release_region(unsigned port, unsigned size) ! 74: { ! 75: unsigned i; ! 76: ! 77: for (i = port; i < port + size; i++) ! 78: port_bitmap[i / BITS_PER_WORD] &= ~(1 << (i % BITS_PER_WORD)); ! 79: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.