Annotation of embedaddon/pciutils/lib/pread.h, revision 1.1
1.1 ! misho 1: /*
! 2: * The PCI Library -- Portable interface to pread() and pwrite()
! 3: *
! 4: * Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
! 5: *
! 6: * Can be freely distributed and used under the terms of the GNU GPL.
! 7: */
! 8:
! 9: /*
! 10: * We'd like to use pread/pwrite for configuration space accesses, but
! 11: * unfortunately it isn't simple at all since all libc's until glibc 2.1
! 12: * don't define it.
! 13: */
! 14:
! 15: #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
! 16: /* glibc 2.1 or newer -> pread/pwrite supported automatically */
! 17:
! 18: #elif defined(i386) && defined(__GLIBC__)
! 19: /* glibc 2.0 on i386 -> call syscalls directly */
! 20: #include <asm/unistd.h>
! 21: #include <syscall-list.h>
! 22: #ifndef SYS_pread
! 23: #define SYS_pread 180
! 24: #endif
! 25: static int pread(unsigned int fd, void *buf, size_t size, loff_t where)
! 26: { return syscall(SYS_pread, fd, buf, size, where); }
! 27: #ifndef SYS_pwrite
! 28: #define SYS_pwrite 181
! 29: #endif
! 30: static int pwrite(unsigned int fd, void *buf, size_t size, loff_t where)
! 31: { return syscall(SYS_pwrite, fd, buf, size, where); }
! 32:
! 33: #elif defined(i386)
! 34: /* old libc on i386 -> call syscalls directly the old way */
! 35: #include <asm/unistd.h>
! 36: static _syscall5(int, pread, unsigned int, fd, void *, buf, size_t, size, u32, where_lo, u32, where_hi);
! 37: static _syscall5(int, pwrite, unsigned int, fd, void *, buf, size_t, size, u32, where_lo, u32, where_hi);
! 38: static int do_read(struct pci_dev *d UNUSED, int fd, void *buf, size_t size, int where) { return pread(fd, buf, size, where, 0); }
! 39: static int do_write(struct pci_dev *d UNUSED, int fd, void *buf, size_t size, int where) { return pwrite(fd, buf, size, where, 0); }
! 40: #define PCI_HAVE_DO_READ
! 41:
! 42: #else
! 43: /* In all other cases we use lseek/read/write instead to be safe */
! 44: #define make_rw_glue(op) \
! 45: static int do_##op(struct pci_dev *d, int fd, void *buf, size_t size, int where) \
! 46: { \
! 47: struct pci_access *a = d->access; \
! 48: int r; \
! 49: if (a->fd_pos != where && lseek(fd, where, SEEK_SET) < 0) \
! 50: return -1; \
! 51: r = op(fd, buf, size); \
! 52: if (r < 0) \
! 53: a->fd_pos = -1; \
! 54: else \
! 55: a->fd_pos = where + r; \
! 56: return r; \
! 57: }
! 58: make_rw_glue(read)
! 59: make_rw_glue(write)
! 60: #define PCI_HAVE_DO_READ
! 61: #endif
! 62:
! 63: #ifndef PCI_HAVE_DO_READ
! 64: #define do_read(d,f,b,l,p) pread(f,b,l,p)
! 65: #define do_write(d,f,b,l,p) pwrite(f,b,l,p)
! 66: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>