Commit Graph

21 Commits (91ec61f8f01cf32868e2ed2fa96a299e77964055)

Author SHA1 Message Date
Ian Abbott e9166139f6 staging: comedi: complain if dma buffer allocation not supported
When allocating a buffer to support asynchronous comedi commands, if a
DMA coherent buffer was requested but `CONFIG_HAS_DMA` is undefined,
bail out of local helper function `__comedi_buf_alloc()` with an error
message.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-05-13 17:38:48 -04:00
Ian Abbott 4efc4bbdc1 staging: comedi: work without HAS_DMA
The core "comedi" module and the "mite" helper module for NI PCI devices
both have calls to `dma_alloc_coherent()` and `dma_free_coherent()`.
Those functions are only available if `CONFIG_HAS_DMA` is defined.

Apart from the "mite" module, the functions are only called for comedi
drivers that set `s->async_dma_dir` (where `s` is a pointer to a `struct
comedi_subdevice`) to anything other than `DMA_NONE`.

Change local helper functions `__comedi_buf_alloc()` and
`__comedi_buf_free()` to only call `dma_alloc_coherent()` and
`dma_free_coherent()` if `CONFIG_HAS_DMA` is defined.

Change the "Kconfig" to make the following configuration options depend
on `HAS_DMA`:

`COMEDI_MITE` - builds the "mite" module.
`COMEDI_NI_6527` - selects `COMEDI_MITE`.
`COMEDI_NI_65XX` - selects `COMEDI_MITE`.
`COMEDI_NI_670X` - selects `COMEDI_MITE`.
`COMEDI_NI_LABPC_PCI` - selects `COMEDI_MITE`.
`COMEDI_NI_PCIDIO` - selects `COMEDI_MITE`.
`COMEDI_NI_TIOCMD` - selects `COMEDI_MITE`.
`COMEDI_NI_660X` - selects `COMEDI_NI_TIOCMD`,
                   sets `s->async_dma_dir`.
`COMEDI_NI_PCIMIO` - selects `COMEDI_NI_TIOCMD`,
                     sets `s->async_dma_dir`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-05-13 17:38:46 -04:00
H Hartley Sweeten 5660e74271 staging: comedi: use EXPORT_SYMBOL_GPL() for all exported symbols
Comedi is licensed under GPL. Some if its exports are currently
EXPORT_SYMBOL() and others are EXPORT_SYMBOL_GPL(). Change them all
to EXPORT_SYMBOL_GPL() and see if anyone reports any fall out.

If any of the symbols "need" to be EXPORT_SYMBOL() they will be
addressed as needed.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-04-12 15:09:59 -07:00
H Hartley Sweeten 215040e123 staging: comedi: comedi_buf: remove noise in comedi_buf_read_free()
If an attempt is made to free more bytes than have been allocated
a dev_info message is output and the number of bytes to free is
adjusted to the allocated size.

Telling the user this happened is just noise. Remove the message.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbobbi@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:56:01 -08:00
H Hartley Sweeten 6166ce8787 staging: comedi: comedi_buf: remove noise in comedi_buf_write_free()
If an attempt is made to free more bytes than have been allocated
a dev_info message is output and the number of bytes to free is
adjusted to the allocated size.

Telling the user this happened is just noise. Remove the message.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbobbi@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:56:00 -08:00
H Hartley Sweeten a8f40f463f staging: comedi: comedi_buf: remove unreachable dev_warn in comedi_buf_munge()
Due to the 'while(count < num_bytes)' the computed 'block_size' will
always be a value greater than 0.

Remove the unreachable dev_warn and the (block_size < 0) test.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbobbi@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:56:00 -08:00
H Hartley Sweeten 305a6f3896 staging: comedi: comedi_buf: remove BUG_ON in comedi_buf_munge()
The condition that would trigger this BUG_ON can never occur.

The 'munge_count' will be equal to 'buf_write_count' if all the data
in the buffer has been munged.

Or, the 'munge_count' will be less than the 'buf_write_count' if any
partial samples in the buffer were not munged.

The 'munge_count' will never be greater than the 'buf_write_count'.

Remove the unnecessary BUG_ON.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbobbi@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:56:00 -08:00
H Hartley Sweeten 8ae560a14a staging: comedi: comedi_buf: reorder exported function prototypes
For aesthetic reasons, reorder the prototypes for the exported
comedi_buf_* functions in comedidev.h to follow the function
declarations in comedi_buf.c.

Also, change a couple of the return values from 'unsigned' to
'unsigned int' to match the value actually returned.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:54:00 -08:00
H Hartley Sweeten 8bd650f91b staging: comedi: comedi_buf: don't expose comedi_buf_write_n_allocated()
This helper function is only called by the comedi core in comedi_buf.c
and comedi_fops.c. For aesthetic reasons, move it to comedi_buf.c and
remove the inline. Move the prototype from comedidev.h to comedi_internal.h
so it's not exposed outside the comedi core.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:59 -08:00
H Hartley Sweeten 5b2b64b751 staging: comedi: comedi_buf: don't expose comedi_buf_read_n_allocated()
This helper function is only called in comedi_buf.c. Move it there and
make it static so it's not exposed globally.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:59 -08:00
H Hartley Sweeten 3abfa1066b staging: comedi: comedi_buf: clarify comedi_buf_read_free()
Reword the comment about the need for the smp_mb().

Clarify the check to make sure the number of bytes to free is not
more than the number of bytes allocated.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:59 -08:00
H Hartley Sweeten 034cbd1792 staging: comedi: comedi_buf: clarify comedi_buf_read_alloc()
Clarify the check to make sure the number of bytes to allocate is
available.

Reword the comment about the need for the smp_rmb().

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:59 -08:00
H Hartley Sweeten 43f9137df4 staging: comedi: comedi_buf: cleanup comedi_buf_read_n_available()
For aesthetic reasons, cleanup this function a bit.

Change the (async == NULL) test to simply (!async).

Reword the comment about the need for the smp_rmb()..

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:59 -08:00
H Hartley Sweeten d21af4cbfb staging: comedi: comedi_buf: clarify comedi_buf_write_free()
Use the helper comedi_buf_write_n_allocated() to clarify the check
to make sure the number of bytes to free is not more than the number
of bytes allocated.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:59 -08:00
H Hartley Sweeten 8d4be66947 staging: comedi: comedi_buf: cleanup comedi_buf_munge()
Refactor this function so there is a single return point and only
one BUG_ON check. The BUG_ON needs to be looked at to see if it
can be safely removed.

Clarify the test in the munge loop that checks for a block copy
that would extend pass the end of the prealloc_buf.

Reword the comment about the need for the smp_wmb().

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:59 -08:00
H Hartley Sweeten 47181eab71 staging: comedi: comedi_buf: remove comedi_buf_write_alloc_strict
This function is only called by comedi_buf_put(). Remove it and just
call __comedi_buf_write_alloc() directly with the strict flag set.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:58 -08:00
H Hartley Sweeten f8f76e909b staging: comedi: comedi_buf: factor out common comedi_buf_write_alloc_* code
The only difference between comedi_buf_write_alloc() and the *_strict()
version is that the *_strict() one will only allocate the chunk if it
can completely fulfill the request.

Factor out the common code and add a flag parameter to indicate the 'strict'
usage. Change the exported functions so they are just wrappers around the
common function.

Cleanup the common function a bit and use the comedi_buf_write_n_available()
helper to determine the number of bytes available.

comedi_buf_write_n_available() is not used outside this module so make it
static. Since the only caller is __comedi_buf_write_alloc(), which will
always have a valid async pointer and already has a memory barrier, we
can remove the unnecessary (async == NULL) test as well as the smp_mb().
Also, the rounding of the sample size can be removed since the caller
does not need it.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:58 -08:00
H Hartley Sweeten 61c9fb0eb0 staging: comedi: comedi_buf: rename comedi_reset_async_buf()
For aesthetic reasons, rename this function to comedi_buf_reset(). This
makes all the asynchronous buffer functions have the same namespace.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:58 -08:00
H Hartley Sweeten 6bd7645731 staging: comedi: comedi_buf: factor out new buffer allocation code
The function comedi_buf_alloc() first frees any allocated buffer then,
optionally, allocates a new buffer.

Factor out the new buffer allocation code to a new function. This
allows reducing the indent level and makes the code a bit cleaner.

Also, cleanup to factored out code to make it a bit more concise.
Use a local variable for the current comedi_buf_page being allocated.
This cleans up the ugly line breaks used to keep the lines < 80 chars.

Move the #ifdef'ery for the page protection determination out of the
vmap() call.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:58 -08:00
H Hartley Sweeten 718c4d68d9 staging: comedi: comedi_buf: factor out common code to free the async buffer
The function comedi_buf_alloc() uses two loops to free the async buffer's
buf_page_list. The first one is used at the beginning to deallocate the
current buffer. The second is used to cleanup if the new buffer allocation
fails.

Factor out the common code to a new function.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:58 -08:00
H Hartley Sweeten ea082fb1b0 staging: comedi: separate out comedi_buf_* functions
Create a new file, comedi_buf.c, to hold all the comedi_async buffer
functions. Currently they are all in drivers.c and really don't have
any association with that source file.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:58 -08:00