1997-08-16 14:05:38 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2000-01-14 00:18:06 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999 Nicolas Souchu
|
1997-08-16 14:05:38 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2003-08-24 17:55:58 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
#include <sys/param.h>
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
#include <sys/lock.h>
|
1997-08-16 14:05:38 +00:00
|
|
|
#include <sys/kernel.h>
|
2000-01-14 00:18:06 +00:00
|
|
|
#include <sys/module.h>
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/systm.h>
|
2000-01-14 00:18:06 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
#include <dev/ppbus/ppbconf.h>
|
2008-11-16 17:42:02 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
#include "ppbus_if.h"
|
1997-08-16 14:05:38 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
#include <dev/ppbus/ppbio.h>
|
2008-11-16 17:42:02 +00:00
|
|
|
|
2003-08-22 06:28:45 +00:00
|
|
|
MODULE_VERSION(ppbus, 1);
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
#define DEVTOSOFTC(dev) ((struct ppb_data *)device_get_softc(dev))
|
2008-11-16 17:42:02 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
/*
|
2000-01-14 00:18:06 +00:00
|
|
|
* ppb_poll_bus()
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
2000-01-14 00:18:06 +00:00
|
|
|
* Polls the bus
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
|
|
|
* max is a delay in 10-milliseconds
|
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_poll_bus(device_t bus, int max,
|
With clang 3.9.0, compiling ppbus(4) results in the following warnings:
sys/dev/ppbus/ppb_1284.c:296:46: error: implicit conversion from 'int'
to 'char' changes value from 144 to -112 [-Werror,-Wconstant-conversion]
if ((error = do_peripheral_wait(bus, SELECT | nBUSY, 0))) {
~~~~~~~~~~~~~~~~~~ ~~~~~~~^~~~~~~
sys/dev/ppbus/ppb_1284.c:785:48: error: implicit conversion from 'int'
to 'char' changes value from 240 to -16 [-Werror,-Wconstant-conversion]
if (do_1284_wait(bus, nACK | SELECT | PERROR | nBUSY,
~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
sys/dev/ppbus/ppb_1284.c:786:29: error: implicit conversion from 'int'
to 'char' changes value from 240 to -16 [-Werror,-Wconstant-conversion]
nACK | SELECT | PERROR | nBUSY)) {
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
This is because nBUSY is 0x80, so the plain char argument is wrapped to
a negative value. Fix this in a minimal fashion, by using uint8_t in a
few places.
Reviewed by: emaste
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D7771
2016-09-03 13:48:44 +00:00
|
|
|
uint8_t mask, uint8_t status, int how)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
int i, j, error;
|
With clang 3.9.0, compiling ppbus(4) results in the following warnings:
sys/dev/ppbus/ppb_1284.c:296:46: error: implicit conversion from 'int'
to 'char' changes value from 144 to -112 [-Werror,-Wconstant-conversion]
if ((error = do_peripheral_wait(bus, SELECT | nBUSY, 0))) {
~~~~~~~~~~~~~~~~~~ ~~~~~~~^~~~~~~
sys/dev/ppbus/ppb_1284.c:785:48: error: implicit conversion from 'int'
to 'char' changes value from 240 to -16 [-Werror,-Wconstant-conversion]
if (do_1284_wait(bus, nACK | SELECT | PERROR | nBUSY,
~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
sys/dev/ppbus/ppb_1284.c:786:29: error: implicit conversion from 'int'
to 'char' changes value from 240 to -16 [-Werror,-Wconstant-conversion]
nACK | SELECT | PERROR | nBUSY)) {
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
This is because nBUSY is 0x80, so the plain char argument is wrapped to
a negative value. Fix this in a minimal fashion, by using uint8_t in a
few places.
Reviewed by: emaste
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D7771
2016-09-03 13:48:44 +00:00
|
|
|
uint8_t r;
|
1999-01-10 12:04:56 +00:00
|
|
|
|
2011-11-22 11:35:24 +00:00
|
|
|
ppb_assert_locked(bus);
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* try at least up to 10ms */
|
|
|
|
for (j = 0; j < ((how & PPB_POLL) ? max : 1); j++) {
|
|
|
|
for (i = 0; i < 10000; i++) {
|
2000-01-14 00:18:06 +00:00
|
|
|
r = ppb_rstr(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(1);
|
|
|
|
if ((r & mask) == status)
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
if (!(how & PPB_POLL)) {
|
|
|
|
for (i = 0; max == PPB_FOREVER || i < max-1; i++) {
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((ppb_rstr(bus) & mask) == status)
|
1997-08-16 14:05:38 +00:00
|
|
|
return (0);
|
|
|
|
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
/* wait 10 ms */
|
|
|
|
error = mtx_sleep((caddr_t)bus, ppb->ppc_lock, PPBPRI |
|
|
|
|
(how == PPB_NOINTR ? 0 : PCATCH), "ppbpoll", hz/100);
|
|
|
|
if (error != EWOULDBLOCK)
|
|
|
|
return (error);
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (EWOULDBLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-01-14 00:18:06 +00:00
|
|
|
* ppb_get_epp_protocol()
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
2000-01-14 00:18:06 +00:00
|
|
|
* Return the chipset EPP protocol
|
1997-08-16 14:05:38 +00:00
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_get_epp_protocol(device_t bus)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
uintptr_t protocol;
|
|
|
|
|
2011-11-22 11:35:24 +00:00
|
|
|
ppb_assert_locked(bus);
|
2000-01-14 00:18:06 +00:00
|
|
|
BUS_READ_IVAR(device_get_parent(bus), bus, PPC_IVAR_EPP_PROTO, &protocol);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
return (protocol);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_get_mode()
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ppb_get_mode(device_t bus)
|
|
|
|
{
|
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1998-08-03 19:14:33 +00:00
|
|
|
/* XXX yet device mode = ppbus mode = chipset mode */
|
2011-11-22 11:35:24 +00:00
|
|
|
ppb_assert_locked(bus);
|
2000-01-14 00:18:06 +00:00
|
|
|
return (ppb->mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_set_mode()
|
|
|
|
*
|
|
|
|
* Set the operating mode of the chipset, return the previous mode
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ppb_set_mode(device_t bus, int mode)
|
|
|
|
{
|
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
int old_mode = ppb_get_mode(bus);
|
|
|
|
|
2011-11-22 11:35:24 +00:00
|
|
|
ppb_assert_locked(bus);
|
2000-07-18 20:16:16 +00:00
|
|
|
if (PPBUS_SETMODE(device_get_parent(bus), mode))
|
2008-11-16 17:42:02 +00:00
|
|
|
return (-1);
|
2000-07-18 20:16:16 +00:00
|
|
|
|
|
|
|
/* XXX yet device mode = ppbus mode = chipset mode */
|
|
|
|
ppb->mode = (mode & PPB_MASK);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1998-08-03 19:14:33 +00:00
|
|
|
return (old_mode);
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/*
|
|
|
|
* ppb_write()
|
|
|
|
*
|
|
|
|
* Write charaters to the port
|
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_write(device_t bus, char *buf, int len, int how)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
|
2011-11-22 11:35:24 +00:00
|
|
|
ppb_assert_locked(bus);
|
2000-01-14 00:18:06 +00:00
|
|
|
return (PPBUS_WRITE(device_get_parent(bus), buf, len, how));
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
/*
|
1998-08-03 19:14:33 +00:00
|
|
|
* ppb_reset_epp_timeout()
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
1998-08-03 19:14:33 +00:00
|
|
|
* Reset the EPP timeout bit in the status register
|
1997-08-16 14:05:38 +00:00
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_reset_epp_timeout(device_t bus)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
|
2011-11-22 11:35:24 +00:00
|
|
|
ppb_assert_locked(bus);
|
2000-01-14 00:18:06 +00:00
|
|
|
return(PPBUS_RESET_EPP(device_get_parent(bus)));
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-08-03 19:14:33 +00:00
|
|
|
* ppb_ecp_sync()
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
1998-08-03 19:14:33 +00:00
|
|
|
* Wait for the ECP FIFO to be empty
|
1997-08-16 14:05:38 +00:00
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_ecp_sync(device_t bus)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
|
2011-11-22 11:35:24 +00:00
|
|
|
ppb_assert_locked(bus);
|
2000-01-14 00:18:06 +00:00
|
|
|
return (PPBUS_ECP_SYNC(device_get_parent(bus)));
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_get_status()
|
|
|
|
*
|
1998-08-03 19:14:33 +00:00
|
|
|
* Read the status register and update the status info
|
1997-08-16 14:05:38 +00:00
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_get_status(device_t bus, struct ppb_status *status)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
With clang 3.9.0, compiling ppbus(4) results in the following warnings:
sys/dev/ppbus/ppb_1284.c:296:46: error: implicit conversion from 'int'
to 'char' changes value from 144 to -112 [-Werror,-Wconstant-conversion]
if ((error = do_peripheral_wait(bus, SELECT | nBUSY, 0))) {
~~~~~~~~~~~~~~~~~~ ~~~~~~~^~~~~~~
sys/dev/ppbus/ppb_1284.c:785:48: error: implicit conversion from 'int'
to 'char' changes value from 240 to -16 [-Werror,-Wconstant-conversion]
if (do_1284_wait(bus, nACK | SELECT | PERROR | nBUSY,
~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
sys/dev/ppbus/ppb_1284.c:786:29: error: implicit conversion from 'int'
to 'char' changes value from 240 to -16 [-Werror,-Wconstant-conversion]
nACK | SELECT | PERROR | nBUSY)) {
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
This is because nBUSY is 0x80, so the plain char argument is wrapped to
a negative value. Fix this in a minimal fashion, by using uint8_t in a
few places.
Reviewed by: emaste
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D7771
2016-09-03 13:48:44 +00:00
|
|
|
uint8_t r;
|
1997-08-16 14:05:38 +00:00
|
|
|
|
2011-11-22 11:35:24 +00:00
|
|
|
ppb_assert_locked(bus);
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
r = status->status = ppb_rstr(bus);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
status->timeout = r & TIMEOUT;
|
|
|
|
status->error = !(r & nFAULT);
|
|
|
|
status->select = r & SELECT;
|
1998-09-13 18:26:26 +00:00
|
|
|
status->paper_end = r & PERROR;
|
1997-08-16 14:05:38 +00:00
|
|
|
status->ack = !(r & nACK);
|
|
|
|
status->busy = !(r & nBUSY);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ppb_lock(device_t bus)
|
|
|
|
{
|
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
|
|
|
|
mtx_lock(ppb->ppc_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ppb_unlock(device_t bus)
|
|
|
|
{
|
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
|
|
|
|
mtx_unlock(ppb->ppc_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ppb_assert_locked(device_t bus, const char *file, int line)
|
|
|
|
{
|
|
|
|
|
2011-11-20 16:33:09 +00:00
|
|
|
mtx_assert_(DEVTOSOFTC(bus)->ppc_lock, MA_OWNED, file, line);
|
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
2009-01-21 23:10:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ppb_init_callout(device_t bus, struct callout *c, int flags)
|
|
|
|
{
|
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
|
|
|
|
callout_init_mtx(c, ppb->ppc_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ppb_sleep(device_t bus, void *wchan, int priority, const char *wmesg, int timo)
|
|
|
|
{
|
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
|
|
|
|
return (mtx_sleep(wchan, ppb->ppc_lock, priority, wmesg, timo));
|
|
|
|
}
|