FreeBSD/sys/dev/terasic/mtl/terasic_mtl_pixel.c
/*
 * All I/O to/from the MTL pixel device must be 32-bit, and aligned to 32-bit.
 */
All I/O to/from the MTL pixel device must be 32-bit, and aligned to 32-bit.
All I / O to / from the MTL pixel device must be 32 - bit and aligned to 32 - bit .
static int
terasic_mtl_pixel_read(struct cdev *dev, struct uio *uio, int flag)
{
	struct terasic_mtl_softc *sc;
	u_long offset, size;
	uint32_t v;
	int error;
	if (uio->uio_offset < 0 || uio->uio_offset % 4 != 0 ||
	    uio->uio_resid % 4 != 0)
		return (ENODEV);
	sc = dev->si_drv1;
	size = rman_get_size(sc->mtl_pixel_res);
	error = 0;
	if ((uio->uio_offset + uio->uio_resid < 0) ||
	    (uio->uio_offset + uio->uio_resid > size))
		return (ENODEV);
	while (uio->uio_resid > 0) {
		offset = uio->uio_offset;
		if (offset + sizeof(v) > size)
			return (ENODEV);
		v = bus_read_4(sc->mtl_pixel_res, offset);
		error = uiomove(&v, sizeof(v), uio);
		if (error)
			return (error);
	}
	return (error);
}
static int terasic_mtl_pixel_read ( struct cdev * dev , struct uio * uio , int flag ) { struct terasic_mtl_softc * sc ; u_long offset , size ; uint32_t v ; int error ; if ( uio -> uio_offset < 0 || uio -> uio_offset % 4 != 0 || uio -> uio_resid % 4 != 0 ) return ( ENODEV ) ; sc = dev -> si_drv1 ; size = rman_get_size ( sc -> mtl_pixel_res ) ; error = 0 ; if ( ( uio -> uio_offset + uio -> uio_resid < 0 ) || ( uio -> uio_offset + uio -> uio_resid > size ) ) return ( ENODEV ) ; while ( uio -> uio_resid > 0 ) { offset = uio -> uio_offset ; if ( offset + sizeof ( v ) > size ) return ( ENODEV ) ; v = bus_read_4 ( sc -> mtl_pixel_res , offset ) ; error = uiomove ( & v , sizeof ( v ) , uio ) ; if ( error ) return ( error ) ; } return ( error ) ; }
All I/O to/from the MTL pixel device must be 32-bit, and aligned to 32-bit.
All I / O to / from the MTL pixel device must be 32 - bit and aligned to 32 - bit .