History log of /freebsd-current/sys/dev/pccbb/pccbb.c
Revision Date Author Comments
# 9dbf5b0e 13-Mar-2024 John Baldwin <jhb@FreeBSD.org>

new-bus: Remove the 'rid' and 'type' arguments from BUS_RELEASE_RESOURCE

The public bus_release_resource() API still accepts both forms, but
the internal kobj method no longer passes the arguments.
Implementations which need the rid or type now use rman_get_rid() or
rman_get_type() to fetch the value from the allocated resource.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D44131


# 2baed46e 13-Mar-2024 John Baldwin <jhb@FreeBSD.org>

new-bus: Remove the 'rid' and 'type' arguments from BUS_*ACTIVATE_RESOURCE

The public bus_activate/deactivate_resource() API still accepts both
forms, but the internal kobj methods no longer pass the arguments.
Implementations which need the rid or type now use rman_get_rid() or
rman_get_type() to fetch the value from the allocated resource.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D44130


# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 6ab0dfe5 06-May-2022 John Baldwin <jhb@FreeBSD.org>

pccbb: Remove unused devclass argument to DRIVER_MODULE.


# 22405bb2 25-Dec-2021 Alexander Motin <mav@FreeBSD.org>

pccbb: Remove Giant mention in comments.

MFC after: 2 weeks


# ba9f0c72 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

pccbb: clean up empty lines in .c and .h files


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# 84e6c29c 16-Dec-2019 Warner Losh <imp@FreeBSD.org>

Add back accidentally dropped masking...

- PCI_MASK_CONFIG(sc->dev, CBBR_BRIDGECTRL,
- & ~CBBM_BRIDGECTRL_INTR_IREQ_ISA_EN, 2);

was accidentally dropped from r355822 in the refactor. Restore it since 16-bit
cards may fail without it (some bridges autodetect this properly, so my laptop
worked when I tested it).

Noticed by: rpokala@


# 1187f0ca 16-Dec-2019 Warner Losh <imp@FreeBSD.org>

Add slot number ivar to return which slot number the child is attached to.

This will always be 0 for pccbb, but may be non-zero for other kinds of bridges,
should they show up in the tree. Make querying it generic.


# 7b9439d0 16-Dec-2019 Warner Losh <imp@FreeBSD.org>

We'll never have multiple slots a cardbus bridge. So, replace exca
array with a singleton.

Also, pccbb isa attachment is never going to happen, do disconnect it from the
build (will delete this in future commit). It would need to be updated as well,
but since this code is effectively dead code, remove it from the build instead.


# f86e6000 04-Dec-2019 Warner Losh <imp@FreeBSD.org>

Regularize my copyright notice

o Remove All Rights Reserved from my notices
o imp@FreeBSD.org everywhere
o regularize punctiation, eliminate date ranges
o Make sure that it's clear that I don't claim All Rights reserved by listing
All Rights Reserved on same line as other copyright holders (but not
me). Other such holders are also listed last where it's clear.


# 7afbd605 06-Jan-2019 Warner Losh <imp@FreeBSD.org>

Fix TI PCI1520 PCI Cardbus bridge, but others affected.

On system with Celeron 1.5GHz CPU, sometimes when a PCMCIA to Compact Flash
adapter containing a Compact Flash card is inserted in the cardbus slot the
system hangs. This problem has not been observed in systems with a 2.8GHz
XEON CPU or faster.

Analysis of the cbb driver shows functional interrupts are routed to PCI
BEFORE the interrupt handler for functional interrupts has been registered.

Fix applied as described in the bug.

PR: 128040
Submitted by: Arthur Hartwig


# b0af0605 04-Jul-2018 Andriy Gapon <avg@FreeBSD.org>

remove unneeded inclusion of sys/interrupt.h from several files

It's likely that the header was needed in the past for swi(9).
But now that code does not use swi(9) or any other interfaces defined
in sys/interrupt.h.

MFC after: 1 week


# 4e96c99b 20-Mar-2018 Warner Losh <imp@FreeBSD.org>

Push down Giant one layer. In the days of yore, back when Penitums
were the new kids on the block and F00F hacks were all the rage, one
needed to take out Giant to do anything moderately complicated with
the VM, mappings and such. So the pccard / cardbus code held Giant for
the entire insertion or removal process.

Today, the VM is MP safe. The lock is only needed for dealing with
newbus things. Move locking and unlocking Giant to be only around
adding and probing devices in pccard and cardbus.


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 453130d9 02-May-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: minor spelling fixes.

Most affect comments, very few have user-visible effects.


# d9c9c81c 21-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sys: use our roundup2/rounddown2() macros when param.h is available.

rounddown2 tends to produce longer lines than the original code
and when the code has a high indentation level it was not really
advantageous to do the replacement.

This tries to strike a balance between readability using the macros
and flexibility of having the expressions, so not everything is
converted.


# da1b038a 17-Mar-2016 Justin Hibbits <jhibbits@FreeBSD.org>

Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.

On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).

Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.

Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)

Tested PAE and devinfo on virtualbox (live CD)

Special thanks to bz for his testing on ARM.

Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544


# 2dd1bdf1 26-Jan-2016 Justin Hibbits <jhibbits@FreeBSD.org>

Convert rman to use rman_res_t instead of u_long

Summary:
Migrate to using the semi-opaque type rman_res_t to specify rman resources. For
now, this is still compatible with u_long.

This is step one in migrating rman to use uintmax_t for resources instead of
u_long.

Going forward, this could feasibly be used to specify architecture-specific
definitions of resource ranges, rather than baking a specific integer type into
the API.

This change has been broken out to facilitate MFC'ing drivers back to 10 without
breaking ABI.

Reviewed By: jhb
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D5075


# e64ac86e 21-Aug-2015 Warner Losh <imp@FreeBSD.org>

We're waiting on a struct proc *, not a struct thread *. Fix a
comment that was wrong.


# 8e5f7614 17-Feb-2015 Warner Losh <imp@FreeBSD.org>

On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:

cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)

All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.

Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.


# 53d67399 15-Jan-2015 Warner Losh <imp@FreeBSD.org>

Move the suspsned and resume functions to the bus attachment. They
were accessing PCI config registers, which won't work for the ISA
version.


# 47a66ea8 15-Jan-2015 Warner Losh <imp@FreeBSD.org>

Suspend and resume were the only two functions not to follow the brdev
convention here, so fix that.


# b45c7d14 15-Jan-2015 Warner Losh <imp@FreeBSD.org>

Back out the refactor. It turns out to cause interrupt storms on
resume sometimes (but not others). On powerup, other wierd issues show
up (sometimes the card comes up, but with really bogus pci config
space stuff. There may be more, but given my experience of historical
fussiness, stick to what works and make more minimal changes to that.


# 8b91d5b0 13-Jan-2015 Warner Losh <imp@FreeBSD.org>

Various interrelated fixes to make suspend / resume work better. We now
can suspend / resume and unload / load cbb and cardbus without errors
on my Lenovo T400, which wasn't possible before. Cards suspending
and resuming in the CardBus slot not yet tested.
o Enable memory cycles to the bridge early (as part of the new
cbb_pci_bridge_init). This fixes the Bad VCC errors which were
caused by the code accessing the device registers with this
cleared. The suspend / resume process clears it.
o Refactor suspend / resume into bus specific code (though the ISA
code is just stubbed). This isn't strictly necessary, but makes
the initializaiton code more uniform and should be more bullet
proof in the face of variant behavior among cardbus bridges.
o Fixup comments in the power-up sequence to reflect reality. These
comments were written for one regime of power-up, but not updated
as things were revised.
o Add a paranoid small delay (100ms) to cover noisy cards powering
down.
o Fix some debugging prints to be easier to grep from dmesg.

Sponsored by: Netflix


# 260a867f 18-Nov-2014 Warner Losh <imp@FreeBSD.org>

Fix typo pointed out by avg@ and Joerg Sonnenberger. Add a clarifying
sentence too.

Sponsored by: Netflix


# 7bfa86f6 17-Nov-2014 Warner Losh <imp@FreeBSD.org>

Modernize comments about BIOSes being lame since in this detail they
aren't lame, the rules changed along the way. Catch up to 1999 or so
with the new rules.


# 707767a8 17-Nov-2014 Warner Losh <imp@FreeBSD.org>

Remove stray empty comment. The code is adequately explained in the
block comment above, so there's nothing to add here.


# af3b2549 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Pull in r267961 and r267973 again. Fix for issues reported will follow.


# 37a107a4 27-Jun-2014 Glen Barber <gjb@FreeBSD.org>

Revert r267961, r267973:

These changes prevent sysctl(8) from returning proper output,
such as:

1) no output from sysctl(8)
2) erroneously returning ENOMEM with tools like truss(1)
or uname(1)
truss: can not get etype: Cannot allocate memory


# 3da1cf1e 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Extend the meaning of the CTLFLAG_TUN flag to automatically check if
there is an environment variable which shall initialize the SYSCTL
during early boot. This works for all SYSCTL types both statically and
dynamically created ones, except for the SYSCTL NODE type and SYSCTLs
which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to
be used in the case a tunable sysctl has a custom initialisation
function allowing the sysctl to still be marked as a tunable. The
kernel SYSCTL API is mostly the same, with a few exceptions for some
special operations like iterating childrens of a static/extern SYSCTL
node. This operation should probably be made into a factored out
common macro, hence some device drivers use this. The reason for
changing the SYSCTL API was the need for a SYSCTL parent OID pointer
and not only the SYSCTL parent OID list pointer in order to quickly
generate the sysctl path. The motivation behind this patch is to avoid
parameter loading cludges inside the OFED driver subsystem. Instead of
adding special code to the OFED driver subsystem to post-load tunables
into dynamically created sysctls, we generalize this in the kernel.

Other changes:
- Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask"
to "hw.pcic.intr_mask".
- Removed redundant TUNABLE statements throughout the kernel.
- Some minor code rewrites in connection to removing not needed
TUNABLE statements.
- Added a missing SYSCTL_DECL().
- Wrapped two very long lines.
- Avoid malloc()/free() inside sysctl string handling, in case it is
called to initialize a sysctl from a tunable, hence malloc()/free() is
not ready when sysctls from the sysctl dataset are registered.
- Bumped FreeBSD version to indicate SYSCTL API change.

MFC after: 2 weeks
Sponsored by: Mellanox Technologies


# 4edef187 11-Feb-2014 John Baldwin <jhb@FreeBSD.org>

Add support for managing PCI bus numbers. As with BARs and PCI-PCI bridge
I/O windows, the default is to preserve the firmware-assigned resources.
PCI bus numbers are only managed if NEW_PCIB is enabled and the architecture
defines a PCI_RES_BUS resource type.
- Add a helper API to create top-level PCI bus resource managers for each
PCI domain/segment. Host-PCI bridge drivers use this API to allocate
bus numbers from their associated domain.
- Change the PCI bus and CardBus drivers to allocate a bus resource for
their bus number from the parent PCI bridge device.
- Change the PCI-PCI and PCI-CardBus bridge drivers to allocate the
full range of bus numbers from secbus to subbus from their parent bridge.
The drivers also always program their primary bus register. The bridge
drivers also support growing their bus range by extending the bus resource
and updating subbus to match the larger range.
- Add support for managing PCI bus resources to the Host-PCI bridge drivers
used for amd64 and i386 (acpi_pcib, mptable_pcib, legacy_pcib, and qpi_pcib).
- Define a PCI_RES_BUS resource type for amd64 and i386.

Reviewed by: imp
MFC after: 1 month


# d53497cc 27-Jan-2014 John Baldwin <jhb@FreeBSD.org>

Explicitly enable I/O and memory decoding in the bridge's command register
when activating an I/O or memory window on the CardBus bridge.

Tested by: Olivier Cochard-Labbe <olivier@cochard.me>
Reviewed by: imp
MFC after: 3 days


# dbd618bf 27-Jan-2012 Warner Losh <imp@FreeBSD.org>

Some laptops have weak power controllers that cannot tolerate multiple
cards powering up at once. Work around the easy case (multiple cards
inserted on boot) with a short sleep and a long comment. This
improves reliability on those laptops with power hungry cards.


# 6472ac3d 07-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.

The SYSCTL_NODE macro defines a list that stores all child-elements of
that node. If there's no SYSCTL_DECL macro anywhere else, there's no
reason why it shouldn't be static.


# cf95dbae 17-Jun-2011 Warner Losh <imp@FreeBSD.org>

More expeirmentation suggests that 10ms isn't as reliable as
previously thought, but 100ms seems to be. Likely there's a good
middle ground, but for now be conservative.


# 0b96c05a 17-Jun-2011 Warner Losh <imp@FreeBSD.org>

After we get a good power signal, always wait about 10ms before
proceeding.

On boot, some laptops with certain cards in them sometimes fail on
boot, but if the card is inserted after boot it works. Experiments
show that small delays here makes things more reliable. It is
believed that some combinations need a little more time before the
power on the card is really stable enough to be reliable once the
power is stable in the bridge.


# 6dc7dc9a 12-Jan-2011 Matthew D Fleming <mdf@FreeBSD.org>

sysctl(9) cleanup checkpoint: amd64 GENERIC builds cleanly.

Commit the rest of the devices.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 247db074 20-Aug-2009 John Baldwin <jhb@FreeBSD.org>

MFC 196403: Temporarily revert the new-bus locking for 8.0 release.

Approved by: re (kib)


# a56fe095 20-Aug-2009 John Baldwin <jhb@FreeBSD.org>

Temporarily revert the new-bus locking for 8.0 release. It will be
reintroduced after HEAD is reopened for commits by re@.

Approved by: re (kib), attilio


# 444b9186 02-Aug-2009 Attilio Rao <attilio@FreeBSD.org>

Make the newbus subsystem Giant free by adding the new newbus sxlock.
The newbus lock is responsible for protecting newbus internIal structures,
device states and devclass flags. It is necessary to hold it when all
such datas are accessed. For the other operations, softc locking should
ensure enough protection to avoid races.

Newbus lock is automatically held when virtual operations on the device
and bus are invoked when loading the driver or when the suspend/resume
take place. For other 'spourious' operations trying to access/modify
the newbus topology, newbus lock needs to be automatically acquired and
dropped.

For the moment Giant is also acquired in some key point (modules subsystem)
in order to avoid problems before the 8.0 release as module handlers could
make assumptions about it. This Giant locking should go just after
the release happens.

Please keep in mind that the public interface can be expanded in order
to provide more support, if there are really necessities at some point
and also some bugs could arise as long as the patch needs a bit of
further testing.

Bump __FreeBSD_version in order to reflect the newbus lock introduction.

Reviewed by: ed, hps, jhb, imp, mav, scottl
No answer by: ariff, thompsa, yongari
Tested by: pho,
G. Trematerra <giovanni dot trematerra at gmail dot com>,
Brandon Gooch <jamesbrandongooch at gmail dot com>
Sponsored by: Yahoo! Incorporated
Approved by: re (ksmith)


# bca6fb92 12-Mar-2009 Warner Losh <imp@FreeBSD.org>

Better name for this routine... it doesn't reset the card, but resets
the power to the card...


# 993b1ae2 16-Feb-2009 Warner Losh <imp@FreeBSD.org>

Hold off root mounting until we've gone through the loop of our thread
almost once. After we've configured the devices that were present the
first time through, then we know that we're done. If the device has
other devices that are deferred, then it must do a similar dance.
This catches both PC Cards and CardBus cards.


# a620f9a5 04-Feb-2009 Warner Losh <imp@FreeBSD.org>

Correct signatures to match kobj function definitions.


# f2323a47 07-Dec-2008 Warner Losh <imp@FreeBSD.org>

Minor tweaks to some of the comments. Also, add a XXX wondering if we
need to frob the 16-bit EXCA registers during the new interrupt-driven
power-up sequence.


# a5d1eba6 07-Dec-2008 Warner Losh <imp@FreeBSD.org>

Use '0' rather than PZERO to not change the priority that I'm waiting
at. I don't think this will make a huge difference, but I have
received a report of a interrupt storm on one 16-bit card that this
might fix (chances are it won't, since I think that we may need to
check both the CBB registers for the 16-bit card as well as the PCIC
registers for power state change).

Submitted by: jhb@


# 5b9ee137 04-Dec-2008 Warner Losh <imp@FreeBSD.org>

Move to using filter for the change interrupts. Also rework the power
interrupt code to be more robust. I've been running these changes for
over a year... With these changes, I don't see the ath card going
into reset like the code in the tree.


# ca446278 04-Dec-2008 Warner Losh <imp@FreeBSD.org>

Minor style nit.


# f40b0e2e 04-Dec-2008 Warner Losh <imp@FreeBSD.org>

Augment comments, and move things around a smidge.


# 414f7ec8 04-Dec-2008 Warner Losh <imp@FreeBSD.org>

Implement a method described in NetBSD PR 36652 for coping with the
BAD VCC bit.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 8e6604f8 10-Aug-2008 Warner Losh <imp@FreeBSD.org>

Read the config space of the child, not the bridge, to determine when
the child is out of reset... <blush>


# d1a8ac92 09-Aug-2008 Warner Losh <imp@FreeBSD.org>

fix typo

Submitted by: N.J. Mann


# e6501bf1 09-Aug-2008 Warner Losh <imp@FreeBSD.org>

It turns out that checking the first DWORD register is more reliable
on a variety of cards. Adjust the comments accordingly to match the
code. Even if the vendor chose 0xffff for the device ID, the vendor
ID can't be 0xffff, so the test is still valid from a standards
perspective.


# 1b146a73 09-Aug-2008 Warner Losh <imp@FreeBSD.org>

After some intial testing, there are even slower cards than the ones
that I have. Wait up to 1.1s for the card to become ready. Document
what the standards say, and use that to justify the behavior in the
code: PCI standard says that a card must respond to configuration
cycles within 2^25 cycles after reset goes high, which is
approximately 1s. Therefore, give cards a little break and wait for
up to 1.1s for VENDOR to become valid. Only look at the vendor part
of the ID, since only it can't be 0xffff (although in practice
vendor/device will always be != 0xfffffffff). Include detailed
pointers to standards so epople understand why we're doing what we're
doing and why it just might be OK. Make it clear in the timeout
message that it is just a warning, sinc we try to soldier on as best
we can anyway.

This should eliminate an error message that r181453 produced on
certain Atheros cards.


# bfd58cce 08-Aug-2008 Warner Losh <imp@FreeBSD.org>

Rather than waiting a fixed amount of time, which might not be enough
and also holds things up, check every 20ms to see if we can read the
vendor of device 0.0. It will be 0xffffffff until the card is out of
reset. Always wait at least 20ms, for safety.

I think this is a better fix to the reset problem. However, I did it
as a separate commit in case something bad happens, people can roll
back to the commit before this one to see if that gives them reliable
behavior. I don't have FreeBSD up on enough machines to do exhaustive
testing on all known bridges...


# ae438af6 08-Aug-2008 Warner Losh <imp@FreeBSD.org>

While most bridges can bring a card out of reset in 20ms, there are
some bridge + card combinations that take longer for reasons unknown.
Adjust the timeout to be 100ms on all !RICOH bridges, but leave RICOH
at 400ms. The 400ms is "lore" from other open source projects, and
I've never see my ricoh bridge chips take this long. Maybe it is the
same thing? Maybe a bit should be read instead of a hard-wired pause?

After this adjustment, a few cards that I'd insert and get only:
cbb0: card_power: 3V
cbb0: card_power: 0V
with full debugging enabled would actually try to attach.

Reported by: sam@ (I think)
MFC after: 3 days


# 3745c395 20-Oct-2007 Julian Elischer <julian@FreeBSD.org>

Rename the kthread_xxx (e.g. kthread_create()) calls
to kproc_xxx as they actually make whole processes.
Thos makes way for us to add REAL kthread_create() and friends
that actually make theads. it turns out that most of these
calls actually end up being moved back to the thread version
when it's added. but we need to make this cosmetic change first.

I'd LOVE to do this rename in 7.0 so that we can eventually MFC the
new kthread_xxx() calls.


# 55aaf894 30-Sep-2007 Marius Strobl <marius@FreeBSD.org>

Make the PCI code aware of PCI domains (aka PCI segments) so we can
support machines having multiple independently numbered PCI domains
and don't support reenumeration without ambiguity amongst the
devices as seen by the OS and represented by PCI location strings.
This includes introducing a function pci_find_dbsf(9) which works
like pci_find_bsf(9) but additionally takes a domain number argument
and limiting pci_find_bsf(9) to only search devices in domain 0 (the
only domain in single-domain systems). Bge(4) and ofw_pcibus(4) are
changed to use pci_find_dbsf(9) instead of pci_find_bsf(9) in order
to no longer report false positives when searching for siblings and
dupe devices in the same domain respectively.
Along with this change the sole host-PCI bridge driver converted to
actually make use of PCI domain support is uninorth(4), the others
continue to use domain 0 only for now and need to be converted as
appropriate later on.
Note that this means that the format of the location strings as used
by pciconf(8) has been changed and that consumers of <sys/pciio.h>
potentially need to be recompiled.

Suggested by: jhb
Reviewed by: grehan, jhb, marcel
Approved by: re (kensmith), jhb (PCI maintainer hat)


# 6e878bc7 03-Jun-2007 Warner Losh <imp@FreeBSD.org>

Migrate from setting a CARD_OK flag in a shared word, to setting its
own entry in the softc. This should allow more of cbb_pci_intr() to
migrate to a new cbb_pci_filt() so that we don't have to run cbb's ISR
in almost every case we get an interrupt. We can't just move
cbb_pci_intr into cbb_pci_filt because it does things that aren't safe
to do from a fast interrupt handler, err I mean from a filter. This is
an important first step.

# I wonder if I need to make cardok volatile or not.


# 16f89cb4 03-Jun-2007 Warner Losh <imp@FreeBSD.org>

Don't register cb_func_filt if the client driver doesn't have a filter.
ditto for the isr.

Reviewed/Suggested by: simokawa-san


# cf924571 02-Jun-2007 Warner Losh <imp@FreeBSD.org>

Minor filter tweaks:
o If we don't have a filter, also check to make sure the card is there before
calling the scheduled ISR. This is necessary to help old drivers whose
ISRs can't cope with being called with the hardware missing, which sadly
still exist in the tree. This is the main reason why we have an extra
layer of indirection for cardbus interrupts.
o If the card is no longer present, mark the interrupt as 'handled' rather
than 'stray' because this accounts for why the interrupt happened. Stray
isn't all bad, since there are other filters that would claim it...
o Fix some comments
+ Add comment about why we check for CARD_OK and touch the hardware in both
the filter and ISR.
+ add a note about why we don't care about Giant
+ also note that giant can't be taken out in a filter...
+ Some minor formatting nits on very long comments.


# 97caddee 31-May-2007 Paolo Pisati <piso@FreeBSD.org>

Make the interrupt handler wrapper capable of correctly support filter+ithread handler.

Discussed and reviewed with: bsdimp, simokawa


# 26432f7b 16-May-2007 Warner Losh <imp@FreeBSD.org>

o Don't hold lock over bus_teardown_intr when we're waiting for the
thread to die, since that can cause deadlock with the ISR (in theory).
o Minor cleanup
o comment nit


# af3bdf60 16-May-2007 Warner Losh <imp@FreeBSD.org>

Better message on cbb resource alloc failure


# a9d4f3de 04-Mar-2007 Warner Losh <imp@FreeBSD.org>

Use different wait channel name for second of two sleeps. Minor commentary
addition.


# 8c6c85be 04-Mar-2007 Warner Losh <imp@FreeBSD.org>

Reduce the number of retries to 10 from 20 for not_a_card retry test.
Add some comments to explain how 10 was picked. 20 was completely
arbitrary, at least 10 has some reasoning behind it.

Also, update the comments about how long we sleep to reflect the new,
shorter timeout we use.


# 8410d79d 27-Feb-2007 John Baldwin <jhb@FreeBSD.org>

Use pause() instead of tsleep()'s on the softc pointer that have no
corresponding wakeups. Also, at least some of the comments nearby indicate
that these are fixed-length I/O sleeps.


# ef544f63 22-Feb-2007 Paolo Pisati <piso@FreeBSD.org>

o break newbus api: add a new argument of type driver_filter_t to
bus_setup_intr()

o add an int return code to all fast handlers

o retire INTR_FAST/IH_FAST

For more info: http://docs.freebsd.org/cgi/getmsg.cgi?fetch=465712+0+current/freebsd-current

Reviewed by: many
Approved by: re@


# ca29e6e1 15-Feb-2007 Warner Losh <imp@FreeBSD.org>

Two changes:
(1) change debounce period from 1s to 250ms. This appears to be fine and
speeds things up a little.
(2) In the middle of cbb_pcic_power_disable_socket we write 0 to the EXCA_INTR
register to put the card into reset. However, this turns off CSC
interrupts for TI bridges (and maybe others). So no further card
insertion events would be noticed. To compensate, after we've gone
through the entire power down sequence, turn on EXCA_INTR_ENABLE so
that CSC events happen.

#2 should fix the 'dead slot' problem that has been reported after
card ejection (but only 16-bit cards).


# 21de43a1 15-Feb-2007 Warner Losh <imp@FreeBSD.org>

It turns out that it is easier to not NULL out pccard and cardbus
device pointers. They don't change as the children device drivers
come and go. Rather, check to see if the device is attached where we
would have checked ! NULL. This solves many asymmetries in the code
that likely could lead to crashes when loading/unloading cbb without
one or more of the expected children's driver not present.


# 9d101a95 15-Feb-2007 Warner Losh <imp@FreeBSD.org>

Fix three bugs:
o When detaching all children, try really hard to get all the children
list before giving up. This is based on an observation by hans petter
selasky in his usb p4 branch.
o When rescanning devices after a driver is added, abort if we can't get
the child list with a message.
o when rescanning devices, if the reprobe/attach is successful, save the
device for cardbus/pccard.


# 673c9ca9 12-Aug-2006 Warner Losh <imp@FreeBSD.org>

Batch of changes:
o when turning off the socket for a 16-bit card, write 0 to INTR register
rather than just tying to just clear the rest bit. this seems to fix
card insert detection after an eject on TI bridges (ricoh bridges work
either way, apparently). This is a MFp4.
o Cope better with TOPIC95 bridges on powerup. According to NetBSD driver,
these bridges don't set POWER_STATE, so cope accordingly in our power
code. They also need a little extra time to settle, so do that as well.
o It appears that we need to turn on/off one of the clocks to the card
when we power up/down that socket on a TOPIC97, also from NetBSD.
o TOPIC97 bridges need to specifically enable LV card support. Unconditionally
do this in the hopes that all laptops that have these chips support LV
voltages (they should, since they are required for CardBus).
o TOPIC register name regularization. Registers specific to models of TOPIC
are now called out as such.

# I need a machine with a TOPIC95 for testing.


# 5a535f68 03-Jun-2006 Warner Losh <imp@FreeBSD.org>

Since we turn off the interrupts, we don't need to disestablish
our ISR.


# 7490082f 03-Jun-2006 Warner Losh <imp@FreeBSD.org>

Move shutdown, and pci specific methods into pccbb_pci.c. Many more
are needed still.


# fc7119a7 03-Jun-2006 Warner Losh <imp@FreeBSD.org>

The interrupt routine is pci specific. Move it into pccbb_pci.c.


# 083f44a5 03-Jun-2006 Warner Losh <imp@FreeBSD.org>

Succeed for writing bus value... nobody that calls must care :-(


# 32b35e59 02-Jun-2006 Warner Losh <imp@FreeBSD.org>

Zero out the devices when they are deleted. We can access the pointer after
the bus detaches which can lead to core dumps. This is quite rare.


# 2f6303b0 24-May-2006 Warner Losh <imp@FreeBSD.org>

Suspend the children before we turn off card events in hardware. This
was done, I believe, to work around some cards having issues in the
suspend case. I think that this helped my Sony VAIO TS505 work better
when it had certain wireless cards in it and I did a apm -z. I've not
tested suspend/resume on other laptops in a long time, so I hope this
doesn't cause greif. Please let me know if it does.


# 1b2ec08c 24-May-2006 Warner Losh <imp@FreeBSD.org>

Fix a race when detaching the cbb worker thread. There were a couple
of cases where we didn't take out the lock before setting or clearing
a bit. This apparently can lead to a race at kldunload time (at least
on my Turion64 laptop, never saw it on my Sony Vaio).


# c40da00c 16-May-2006 Poul-Henning Kamp <phk@FreeBSD.org>

Since DELAY() was moved, most <machine/clock.h> #includes have been
unnecessary.


# ebcd5293 16-Apr-2006 Warner Losh <imp@FreeBSD.org>

Add missing ~. We want all the INVALID bits to be 0... Let's see if this
helps people with their interrupt storm problem on card eject.


# a49ed2a6 29-Mar-2006 Warner Losh <imp@FreeBSD.org>

On some laptops, under very high loads, the socket event register read
in the ISR doesn't read the actual socket event register, but instead
reads garbage (usually 0xffffffff, but other times other things).
This totally violates the PCI spec, but happens rarely enough that a
workaround is in order. This adds one test when we have a real
interrupt to service (which is very rare), and doesn't affect the
usualy 'nothing to see here' case at all.

Problem reported by many, but sam@ gave me this workaround after
diagnosing the problem.


# 1ab7d4c9 24-Mar-2006 Warner Losh <imp@FreeBSD.org>

For each of the voltages that a card might support, make sure that the
socket also supports the voltage. Some XV cards have appeared on the
scene (or cards that report they support XV), and in older machines
that have sockets that do not support XV, we were bogusly trying to
power them at XV rather than at 3.3V. Now, power up the card at the
lowest voltage supported by both the card and the socket.

MFC After: 3 days


# 22293c3a 07-Feb-2006 Warner Losh <imp@FreeBSD.org>

Detach the children before we delete them. This is a little cleaner
than just deleting them. Also add comments about why we do this.
Given the current behavior of delete_child, I don't think this changes
anything. It just feels cleaner.


# 44dc92eb 04-Feb-2006 Warner Losh <imp@FreeBSD.org>

Now that TUNABLE_ULONG is in the tree, and has been for a while, use it.
This also avoids typepunning.


# ef8984f5 31-Dec-2005 Warner Losh <imp@FreeBSD.org>

Remove extra debugging that crept in with the integration from p4.


# 3ac60487 29-Dec-2005 Warner Losh <imp@FreeBSD.org>

Simplify the opening of the resources for cardbus cards. Before we'd
try very hard to be perfect. However, these attempts broke down when
there were large numbers of resources. We'd not be able to map them all.

Instead, accept that we might pass more range to thse subbus than
might be optimal be able to compute. However, there's little harm in
this and it allows us to pass greater resources through.

# it has been suggested that we allocate a fixed amount of resources
# on attach and give it out upon request. This might not be a bad idea...


# 0e6e3c13 27-Dec-2005 Warner Losh <imp@FreeBSD.org>

Ensure that we're aligned at leas tto the size of the resource being requested.
When cbb_debug is on, print the windows that we're mapping.


# ba61c672 28-Oct-2005 Warner Losh <imp@FreeBSD.org>

Shutdown a little better by commenting the shutdown code and acknowledging
any interrupts after we turn off the interrupt mask.


# d9a423c3 28-Oct-2005 Warner Losh <imp@FreeBSD.org>

Shut down the card bus bridge hardware on detach. Before we'd just
free the resoruces w/o actually turning off the interrupts. This lead
to interrupt storms if you were to insert a card after kldunloading
the driver.


# f481fa4d 08-Oct-2005 Warner Losh <imp@FreeBSD.org>

MFP4: Changes to hopefully make the new power code work better

o Rather than just try to turn off EXCA_INTR_RESET, set the entire register
to 0. This is slightly faster, and a better hammer.
o Move attempted clearing of the output enable (EXCA_PWRCTL_OE) back to
after we turn off the power. Modify it to write 0 so that we don't get
Bad Vcc messages on TI bridges (untested, but ru@ sent me a similar patch)
while at the same time avoiding interrupt storms on Ricoh bridges (tested
by me on my Sony).

# Many of my observations of 'breakage' for this patch are due to some bug
# in the load/unload of cbb.ko unlreated to this change. I'll be investigating
# and fixing that bug in the fullness of time.


# f1abc0ea 08-Oct-2005 Warner Losh <imp@FreeBSD.org>

MFP4: We no longer use intr_handlers, so remove it.


# ed448ee4 08-Oct-2005 Warner Losh <imp@FreeBSD.org>

MFP4: Note why we do the dance we do for waiting for the thread to die.


# c82f53f6 22-Sep-2005 Warner Losh <imp@FreeBSD.org>

'PC Card' instead of other variants


# 5c4f7048 11-Sep-2005 Warner Losh <imp@FreeBSD.org>

This appears to be good for some folks, but really bad for others.
Until we know why, back out 1.127.


# 8fe5efa8 08-Sep-2005 Warner Losh <imp@FreeBSD.org>

Minor improvement for the suspend case for Ricoh based (and others)
CardBus bridges.


# b32757b4 17-Jul-2005 Warner Losh <imp@FreeBSD.org>

o The ricoh bridge needs us to turn off the function interrupts for
16-bit cards when we're powering them up. Other bridges may have
similar issues, so we do this for all of them by setting the
interrupt in the PCIC register 3 to be 0 (done always anyway)
and turning on the bit in the bridge control register to route these
interrupts via the ISA bus (or via the interrupt configured in the
PCIC register 3). '0' means disable completely. There's a small
chance this may interfere with the o2micro power hacks, but I'll
wait for reports to come in from o2micro users.
o Expand some of the comments about why we do certain things.

# this gets rid of the interrupt storm warnings on my 505TS. I think
# that we may need to do something similar on suspend, but I'm unsure
# since I don't have a laptop that supports suspened/resume with a
# ricoh chipset in it.


# 85ef2343 17-Jul-2005 Warner Losh <imp@FreeBSD.org>

The CD interrupt should only be enabled after we've initialized the
card. Mask it while we're doing power things, as the PC Card standard
suggests. Also, poll the POWER_CYCLE bit 10x a second as well as
providing a timeout for power cycle interrupt to happen.

The Ricoh '475 that I have doesn't seem to generate an interrupt for
power at the present time, so the polling is necessary for reasons as
yet unknown. This results in an interrupt storm warning that I'm
still trying to quantify (the o2micro trick doesn't work to mitigate
this storm). At the very least, this should help those users that
lost pccards on boot with the prior rev of this code. My VAIO
PCG-505TS is now happier, but more investigation is necessary.


# ce71e8d8 14-Jul-2005 Warner Losh <imp@FreeBSD.org>

s/_us//


# d224ede0 14-Jul-2005 Warner Losh <imp@FreeBSD.org>

Move to using tsleeps in the cardbus reset case as well. This
eliminates the last of the DELAYs in pccbb.


# fd4e4752 14-Jul-2005 Warner Losh <imp@FreeBSD.org>

Omnibus power and interrupt fixes:
o Don't busy wait on powerup. Instead, use the power up interrupt to wait
for the card to power up. Don't wait when we're turning the card off,
since no interrupt happens in that case.
o Convert many of the long DELAYs to tsleeps. We do not run before
the timer have stared, so DELAY isn't necessary. More DELAYs can likely
be eliminated in the future.
o When powering up the card, don't do anything if the card is already
powered up (before we'd power cycle it). This means that for most
cards we power them up once and then never change the power.
o On card eject, mask (by clearing) the CD bit. Before we set it, which
was wrong. We don't want to see any CD events past the first one since
they need to be debounced.

With these changes, I can insert/eject 16bit cards without glitching xmms'
sound output. Something very important to the development of better pccard
drivers :-)


# 523675f6 13-Jan-2005 Warner Losh <imp@FreeBSD.org>

Use the standard FreeBSD license for these files.

Approved by: imp, jon


# eb523c72 10-Jan-2005 Warner Losh <imp@FreeBSD.org>

The card activation failured message is lame, and not done for other
busses, nor for the 16-bit cards. Eliminate it.


# afa87f87 10-Jan-2005 Warner Losh <imp@FreeBSD.org>

/* -> /*- for a second clause


# 098ca2bd 05-Jan-2005 Warner Losh <imp@FreeBSD.org>

Start each of the license/copyright comments with /*-, minor shuffle of lines


# 93185c74 12-Aug-2004 Warner Losh <imp@FreeBSD.org>

Move towards isa attachment for pccbb. This is a work in progress, but
works well with the pci attachment.


# d9975d06 22-Jul-2004 Warner Losh <imp@FreeBSD.org>

Add IDs from TI's web site. Reports from the field and inspection of
the data sheets leads me to believe these will just work. Those parts
with the various media readers on them may not have the required
FreeBSD drivers that will attach to the subdevices that will be seen
on some of these parts.

PCI 1515, 1530, 1620, 4520, 6411, 6420, 7410, 7510, 7610

Prompted by: Havard Eidnes


# 284b024b 22-Jul-2004 Warner Losh <imp@FreeBSD.org>

Update comment about fast interrupts to be closer to reality


# b0ba9e25 23-Jun-2004 Warner Losh <imp@FreeBSD.org>

Improve the kludge assignment of sub-bus numbers a little by fixing an
off by one error. subbus must be > than pribus, so the right test is
<= not just <.

Reported by: Peter Losher


# 41ee9f1c 30-May-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Add some missing <sys/module.h> includes which are masked by the
one on death-row in <sys/kernel.h>


# 2a6c850c 21-May-2004 Warner Losh <imp@FreeBSD.org>

When attaching pccard and cardbus children, there's no need to set the
device == NULL on failure. A warning should suffice.

# I wrote this back before I understood the unattached but loosely bound
# newbus concept...


# 2a829b00 21-May-2004 Warner Losh <imp@FreeBSD.org>

Now that we have the resource allocation code in current, the kludge
to try to allocate things on my parent can be taken out. It duplicates code.

Also, add comment about why the power state stuff is here (type 2
devices don't participate in the power state save/restore due to
larger Bx issues).


# 923332f7 03-May-2004 Warner Losh <imp@FreeBSD.org>

Need to mark the interrupt from cbb as being MP safe on resume too.


# 6c92cac9 22-Apr-2004 Warner Losh <imp@FreeBSD.org>

Start programming the bus numbers for the pci<->cardbus. When the
secondary bus is 0, we program the primary bus, the secondary bus and
the suborindate bus. This isn't ideal, since we start at parent_bus +
1 and store this in a static.

Ideally, we'd walk the tree and assign bus numbers. However, that's
harder to accomplish without some help from the bus layer which we're
not planning on doing that until 6.

This fixes my CardBus problems on my Sony PCG-Z1WA, and might fix the
Dells that have had problems.


# 57094462 13-Apr-2004 Warner Losh <imp@FreeBSD.org>

Remove extra copy of code.

Noticed by: Carlos Velasco


# 9b582996 12-Apr-2004 Warner Losh <imp@FreeBSD.org>

MFp4:
Alignment for pccards should also be treated in a similar way that
we tread it for cardbus cards.

Remove bogus debugs while I'm here.

# This is also necessary to make the CIS reading work.

Submitted by: Carlos Velasco


# 0a6c6a6d 06-Apr-2004 Warner Losh <imp@FreeBSD.org>

Better checks to make sure that we get good alignment. This code is a
bit of a bandaide until I get better pci bus code committed to head
from my p4 tree.


# 70fc36e8 06-Apr-2004 Warner Losh <imp@FreeBSD.org>

Fix mis-merge from p4 by adding line getting sc.
Attempt to deal with larger memory allocation better.


# 1ca203ae 06-Apr-2004 Warner Losh <imp@FreeBSD.org>

MFP4: Power up with OE disabled. Similar patches went into NetBSD a
while ago, and it does seem to help at least one card I have and has
been in my p4 tree for many months.


# 5f96beb9 17-Mar-2004 Nate Lawson <njl@FreeBSD.org>

Convert callers to the new bus_alloc_resource_any(9) API.

Submitted by: Mark Santcroos <marks@ripe.net>
Reviewed by: imp, dfr, bde


# 60744399 05-Mar-2004 John Baldwin <jhb@FreeBSD.org>

kthread_exit() no longer requires Giant, so don't force callers to acquire
Giant just to call kthread_exit().

Requested by: many


# 9a6fdece 04-Jan-2004 Warner Losh <imp@FreeBSD.org>

MFp4:
o O2Micro OZ711e1 is now recognized (note: I don't have one, and the current
owner of the Dell laptop is reporting problems).
o minor nits wrt copyright date.


# 3c4c6576 21-Dec-2003 Warner Losh <imp@FreeBSD.org>

Fix typo in ENE CB710 description. It isn't a 720.


# a66f2afd 11-Nov-2003 Warner Losh <imp@FreeBSD.org>

Fix a harmless typo (use of res instead of rle: if rle is NULL, we'd
still get a panic, just not a nice message) and update to new
__FBSDID.

Submitted by: charnier@


# d0ff2e64 07-Nov-2003 Warner Losh <imp@FreeBSD.org>

-Wunused


# 123cd74e 07-Nov-2003 Warner Losh <imp@FreeBSD.org>

Remove channeling interrupts to IRQ1. Some chipsets don't do the
expected thing and that causes interference with keyboards.


# d2bda4e0 24-Oct-2003 Warner Losh <imp@FreeBSD.org>

Backswards is as backwards does: If we're MPSAFE, then we don't need
giant, which implies that we need to take out giant it we're NOT
MPSAFE.

# I can't believe the number of people that looked at this failed to
# detect this.


# 572e53c2 22-Aug-2003 Warner Losh <imp@FreeBSD.org>

Add newly discovered ENE Technologies CardBus bridges to the list:
CB710, CB720, CB1211, CB1225, CB1410 and CB1420
These are likely licensed designed from TI, and the Linux PCMCIA code
treats them as TI chips.

Add comment, but no ID for the 711E1 from O2Micro.


# 38d8c994 22-Aug-2003 Warner Losh <imp@FreeBSD.org>

Prefer new location of pci include files (which have only been in the
tree for two or more years now), except in a few places where there's
code to be compatible with older versions of FreeBSD.


# 08d63b4c 20-Aug-2003 Warner Losh <imp@FreeBSD.org>

In my efforts to make checking the CD bits less error-prone, I
introduced an error. In power_enable_socket, we only return ENODEV if
there isn't a card, not if there is a card. Ooops.

Pointy hat to: bsdimp


# c8c57208 20-Aug-2003 Maxime Henrion <mux@FreeBSD.org>

Fix typo in last commit.


# 74a9cb09 20-Aug-2003 Warner Losh <imp@FreeBSD.org>

Use CBB_CARD_PRESENT instead of checking STATE_CD directly since it is
hard to get right.


# f2d72e24 18-Aug-2003 Warner Losh <imp@FreeBSD.org>

The CD bits in the CBB_SOCKET_STATE register are 0 when the card is
present, and non-zero when it is (or may be) absent. The test
cbb_child_present was backwards. However, typical usage in the tree
would cause it to do the right thing because the card really wasn't
there the OK flag would be turned on.

Also, assume that if any of these bits are turned on we don't have a
card, rather than requiring both of them in the suspend/resume
routines.

Noticed by: cognet


# da245931 17-Aug-2003 Warner Losh <imp@FreeBSD.org>

Put the clearing of the socket cd interrupt and setting of it under
protection of sc->mtx. Sometimes multiple insert/ejections could
cause further insertion/removals to not happen due to racing an ISR...


# fbe15138 14-Aug-2003 Warner Losh <imp@FreeBSD.org>

trivial optimization: use nameunit here.


# 8a0ef7be 09-Aug-2003 Warner Losh <imp@FreeBSD.org>

MF p4:

Minor style(9) nit.


# 2724f321 09-Aug-2003 Warner Losh <imp@FreeBSD.org>

Some bridges, like o2 micro and maybe ricoh, have some issues between
the time the card is inserted and the time that the card is
configured. This can lead to interrupt storms. The O2Micro suggested
workaround is to route the card function interrupt to IRQ1. It
appears from my testing that this is an acceptable workaround for most
chipsets (there's still some issue with the ricoh chipset).

Also, only look at the NOT_A_CARD bit when the bridge tells us there's
a card present. At least one test caused this to be true after the
card was removed, but the author couldn't recreate it with the
workaround in place. The change is more conservative than the
previous code, but still has the work around that wasn't present in
the older code.


# fda5b612 09-Aug-2003 Warner Losh <imp@FreeBSD.org>

Add code to cope more with strange conditions after careful study of
the standard.

1) When the bridge tells us that we have a card that isn't recognized, we
use the force register to force the CV_TEST to run. This test causes the
bridge to re-evaluate the card. Once this re-evaluation process happens,
we get a new interrupt that may say it is ready to process. We try this up
to 20 times. Tests have shown that this appears to correctly reset the
'Unknown card type' problem that I saw on my Sony PCG-505TS.
2) Take a page from OLDCARD and always read the CSC register in the ISR.
Some TI (and it seems maybe Ricoh) chipsets require this to behave
properly. This work around appears to work due to some power management
protocols that were improperly implemented. Maybe it can be removed when
this driver supports the full PME# protocol described in the standards.
3) Minor additional debug printf when debugging is enabled.
4) Minor additional commentary for things that are obvious only after study.

# I'm committing this from my Sony PCG-505TS using shared PCI interrupts
# and NEWCARD, but there are some issues with the Ricoh bridge still, but
# at least now I can boot with the card inserted and have it work.


# 71ed0ee3 09-Aug-2003 Warner Losh <imp@FreeBSD.org>

CBB_SOCKET_STAT_ is too long. Change it to CBB_STATE_. Also, make
some minor changes to more closely match the bit names used in the 7.0
version of the PCMCIA standard. Also add bits from the FORCE
register.


# 69a7c91e 09-Aug-2003 Warner Losh <imp@FreeBSD.org>

When allocating memory, align it to the minimum alignment required for
cardbus bridges if the alignment requirements were less restrictive.


# da57cf7c 09-Aug-2003 Warner Losh <imp@FreeBSD.org>

Add comments about some alignment that looks a little strange.


# e3bf57b6 09-Aug-2003 Warner Losh <imp@FreeBSD.org>

Minor fixes to a couple of comments.


# 8b149b51 07-Aug-2003 John Baldwin <jhb@FreeBSD.org>

Consistently use the BSD u_int and u_short instead of the SYSV uint and
ushort. In most of these files, there was a mixture of both styles and
this change just makes them self-consistent.

Requested by: bde (kern_ktrace.c)


# fa4b32fa 03-Jul-2003 Warner Losh <imp@FreeBSD.org>

All current uses of pci_set_powerstate are bogus, at least in theory.
However, they are presently necessary due to bigger bogusness in the
pci bus layer not doing the right thing on suspend/resume or on
initial device probe. This is exactly the sort of thing that the
BURN_BRIDGES option was invented for. Mark all of them as
BURN_BRIDGES. As soon as I have the powerstate stuff properly
integrated into the pci bus code, I intend to remove all these
workarounds.


# 2b8c22f6 12-Jun-2003 Warner Losh <imp@FreeBSD.org>

Unlock after ISR.

Noticed by: njr
Pointy hat to: the impable one.


# 9b6df37a 11-Jun-2003 Warner Losh <imp@FreeBSD.org>

s/BURN_THE_BOATS/BURN_BRIDGES/g to adopt to new world order


# de5059db 11-Jun-2003 Warner Losh <imp@FreeBSD.org>

Make cbb interrupts MPSAFE:
o Register ISR INTR_MPSAFE.
o Loop on KTHREAD_DONE == 0 in the thread.
o Safe the INTR_MPSAFE flag for client drivers (don't know if there are any
CardBus/PCI drivers that are INTR_MPSAFE)
o Read status after acquiring mtx_lock(Giant) rather than before so that we
catch state changes that happen while Giant is being acquired.
o Turn off the CD bit when we see a CD interrupt, and turn it back on after
we've attached/detached the card.
o On suspend, actually set the CBB_SOCKET_MASK to zero rather than oring
in '0' to turn it off on suspend.
o If the ISR that's registerd is MPSAFE, don't acquire Giant around call to
client ISR.
o Fix comments to reflect these changes.


# e08a16f0 07-Jun-2003 Warner Losh <imp@FreeBSD.org>

MFp4:

Migrate some common pccard code into exca.


# bb22b141 07-Jun-2003 Warner Losh <imp@FreeBSD.org>

Simplify the power code somewhat (this makes the module about 100
bytes smaller).


# e4e7b5bc 06-Jun-2003 Warner Losh <imp@FreeBSD.org>

Add two of three workarounds for interrupt storms for o2micro parts as
obtained from o2micro. These should only be needed for 'older'
o2micro bridges (anything before the 7xxx series of bridges), but will
work with the new bridges.

# I don't plan on porting it to oldcard, but will happily commit to
# oldcard if someone else needs them.


# 4738f8c1 31-May-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Remove return after goto.
Remove break after return;

Found by: FlexeLint


# efc7a12c 04-May-2003 Warner Losh <imp@FreeBSD.org>

Back out accidentally committed debugging


# 45285511 03-May-2003 Warner Losh <imp@FreeBSD.org>

fix typo in TI1515 ID.


# c7611918 28-Apr-2003 Warner Losh <imp@FreeBSD.org>

Fix typo on O2Micro devices names.

Submitted by: noda-san


# 5878ce2c 28-Apr-2003 Warner Losh <imp@FreeBSD.org>

Make IRQ shareable for the cardbus case too.


# 307def65 08-Apr-2003 Warner Losh <imp@FreeBSD.org>

Don't need to read this config register if we're just going to
overwrite it in the next line.


# 9713a792 08-Apr-2003 Warner Losh <imp@FreeBSD.org>

MFp4: Massively unbreak module loading/unloading:
o Only complain about detached children that aren't pccard/cardbus.
o Don't NULL out the pccarddev and cbdev devices. detach just
disassociates the device and driver. It doesn't delete the child.
o on driver added, just probe_and_attach the children. If there's
any children attached, wakeup the device add/delete thread.
o wakeup the add/delete thread with the correct cv_signal() rather
than the bogus wakeup(sc). It used to be that we did a tsleep on
sc in this thread, but switched to the more reliable cv stuff a while
ago w/o changing this.
o Remove bogus checks when reallocating memory for the registers. They
weren't needed and turned out to be completely bogus.

This lets me load/unload pccard with a pccard in a slot and have the
child correctly detach/attach. This should help people that have wi
in their kernel, but that kldload cbb and pccard, for example.


# 2ff0908a 13-Feb-2003 Warner Losh <imp@FreeBSD.org>

o transition from exca_write to exca_putb and read->getb. This is so that
we can have additional different types of bridges.
o remove now bogus comment.
o Don't clear CARD_OK when we can't attach a card.
o minor style nits

# this make kldload of cardbus drivers work for me when the card is
# present on boot.


# e961d904 23-Nov-2002 Warner Losh <imp@FreeBSD.org>

Remove a comple of bogus debug printfs that snuck in during some
debugging I was doing 3 months ago :-(.

Noticed by: scottl
Aproved by: the re blanket (different than the security blanket).


# b20360c8 13-Nov-2002 Warner Losh <imp@FreeBSD.org>

MFp4:
o Add support for bus_child_present call by implementing that method for cbb.


# dfe5056e 13-Nov-2002 Warner Losh <imp@FreeBSD.org>

MFp4:
o Make this code a little easier to understand by using simpler if
statements, but nesting them.


# 518792d8 03-Nov-2002 Warner Losh <imp@FreeBSD.org>

Detach the pccard bus children when we eject a 16-bit card, not the
32-bit ones. This was introduced in the last commit.


# bcaa6b05 02-Nov-2002 Warner Losh <imp@FreeBSD.org>

MFp4:
o Always release the resources on device detach.
o Attach resources the same with driver added as we do we do in the insert
case (maybe this should be a routine).
o signal the wakeup of the thread on resume instead of trying to force an
interrupt.
o Minor debug hacks.
o use 0xffffffff instead of -1 for uint32_t items.
o Don't complain when we're asked to detach no cards. This is normal.
o Eliminate the now worthless second parameter to card_detach_card.
o minor style(9)isms

Some of these patches may be from: iwasaki-san, jhb, iadowse


# 93642ba9 10-Oct-2002 Warner Losh <imp@FreeBSD.org>

o Set CBB_CARD_OK just before CARD_ATTACH_CARD. If ATTACH_CARD fails, then
clear the bit. This allows ata driver to attach its children because
it needs the interrupts enabled to succeed.

Submitted by: iwasaki-san

o Spell CardBus as CardBus, not Cardbus or CardBUS while I'm here.


# c4598a89 07-Oct-2002 Warner Losh <imp@FreeBSD.org>

Make kldunload cbb work:
o Implement the thread killing interlock as described by jhb in arch@
while talking to markm.
o Hold Giant around cbb_insert()/cbb_remove(). Deep in the belly of
the vm code we panic if we don't hold this when we activate the memory
for reading the CIS.
o If we had to do the kludge alloc, then do a kludge free.


# 01d8ff4d 07-Oct-2002 Warner Losh <imp@FreeBSD.org>

MFp4:
o Better resume code. Move the comments around. Force the socket state to
be querried. Ack the interrupts properly.
o Intercept the interrupt requests and keep a list of interrupts to service
ourselves. When the card attaches, set its OK bit. When we get a card
status change interrupt for that card, clear the OK bit. Don't call the
ISR if the OK bit is cleared. Iwasaki-san and yamamoto-san have both
sent me patches that fix the same problem this fixes, but at the pccard
level.
o Try to get the signalling of the thread to actually die. This might not be
100% right, but it is less wrong than before.
o Add a SIC next to a TI type that looks like it could be wrong, but isn't.


# 316ec49a 02-Oct-2002 Scott Long <scottl@FreeBSD.org>

Some kernel threads try to do significant work, and the default KSTACK_PAGES
doesn't give them enough stack to do much before blowing away the pcb.
This adds MI and MD code to allow the allocation of an alternate kstack
who's size can be speficied when calling kthread_create. Passing the
value 0 prevents the alternate kstack from being created. Note that the
ia64 MD code is missing for now, and PowerPC was only partially written
due to the pmap.c being incomplete there.
Though this patch does not modify anything to make use of the alternate
kstack, acpi and usb are good candidates.

Reviewed by: jake, peter, jhb


# b5b06343 10-Sep-2002 Warner Losh <imp@FreeBSD.org>

reprobe not needed here either


# 1739cac2 24-Aug-2002 Marc Fonvieille <blackend@FreeBSD.org>

Fix typos: s/O2Mirco/O2Micro/

Approved by: imp


# b35cf671 15-Aug-2002 Warner Losh <imp@FreeBSD.org>

Rename the pccbb device to cbb.


# 673cffef 10-Aug-2002 Warner Losh <imp@FreeBSD.org>

When we allocate our bus address via the kludge that we have in the
code to do it when the bios doesn't do it for us, flag it. Then, when
we dealloc, do an equal kludge to get rid of the address. This should
address the can't get IRQ and panic bug in a more graceful way.

# really should write a dealloc routine and just call it instead, since
# this might not fix things in the kldunload case.


# 3722c8ed 26-Jul-2002 Warner Losh <imp@FreeBSD.org>

No doubt about it, I gotta get a better hat:

Add the definition for sockbase that I accidentally removed two
revisions ago and didn't notice until some kind soul pointed it out to
me.


# 8948a4fd 26-Jul-2002 Warner Losh <imp@FreeBSD.org>

Looks like a last second change wasn't completely backed out.


# e4188e91 26-Jul-2002 Warner Losh <imp@FreeBSD.org>

MFp4:
o Rename the insanely long PCIC bridge ids.
o Add my copyright to pccbb.c
o Add support for the TI-1510, TI-1520 and TI-4510 series of upcoming
bridges.
o Init MFUNC if it is zero and the TI part has a MFUNC register
at offset 0x8c (1030, 1130 and 1131 don't have anything there, the
1250,1251,1251B and 1450 have a different thing there. The rest
have it. TI is likely to only do MFUNC from now on. The IRQMUX
in the 1250 series of chips needs no tweaks.
o Adjust to new exca interface.
o Add comments about TI chips that I learned in talking to an
engineer at TI.
o Add register definitions for MFUNC.
o Create CB_TI125X chipset type.


# 9e1b56e2 20-Jul-2002 Warner Losh <imp@FreeBSD.org>

Reset the 16-bit bus and turn off power. More work in this area may
be needed, but this seems sane on my laptop.


# 4fdc73e4 13-Jun-2002 Warner Losh <imp@FreeBSD.org>

Use a cv rather than tsleep and friends to do the sleep/wakeup
handshake between the ISR and the worker thread. Move the mutex lock
so that it only protects the cv_wait. This elimiates the not sleeping
with pccbb1 held messages some people were seeing.

Reviewed by: jhb (at least an early version)


# 80f10018 30-May-2002 Takanori Watanabe <takawata@FreeBSD.org>

Make oldcard and newcard kernel module work.


# d76b2f9d 29-Apr-2002 Warner Losh <imp@FreeBSD.org>

Spell hw.cbb.start_memory the same in the HINT as well as the sysctl.

Noted by: bde


# 9ce2d50c 29-Apr-2002 Warner Losh <imp@FreeBSD.org>

Make sysctl RW


# 387a5bac 12-Apr-2002 Warner Losh <imp@FreeBSD.org>

Restore NetBSD copyrights that shouldn't have been removed in the first place.


# 6008862b 04-Apr-2002 John Baldwin <jhb@FreeBSD.org>

Change callers of mtx_init() to pass in an appropriate lock type name. In
most cases NULL is passed, but in some cases such as network driver locks
(which use the MTX_NETWORK_LOCK macro) and UMA zone locks, a name is used.

Tested on: i386, alpha, sparc64


# 4d8f4de4 20-Feb-2002 Warner Losh <imp@FreeBSD.org>

Check the status of the card bridge first thing, rather than last in
the loop. This fixes the "my card is in the laptop on boot, but
doesn't attach" problem.


# c92e45e4 16-Feb-2002 Warner Losh <imp@FreeBSD.org>

Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.

o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.


# 7d8aca49 16-Feb-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

I am sick of being told that "cstsevent occures".


# cebd67fb 09-Feb-2002 Warner Losh <imp@FreeBSD.org>

o Use INTR_TYPE_AV (the highest possible) rather than INTR_TYPE_BIO
o Don't allow INTR_TYPE_FAST. Since we are sharing the interrupt between
CSC and the functions, they can't be FAST because fast interrupts can't
be shared.
o Add the same workaround for resume that we have in OLDCARD.
o Also, return the error from bus_generic_resume rather than ignoring it.


# a0e457a6 04-Feb-2002 Warner Losh <imp@FreeBSD.org>

Default debugging to OFF now.


# 473a3d85 28-Jan-2002 Warner Losh <imp@FreeBSD.org>

Migrate towards using the new exca module for 16bit stuff. This is a
WIP, but works for me.

Also do some minor code factoring and code cleanup while I'm here.


# 5d4be85d 15-Jan-2002 Warner Losh <imp@FreeBSD.org>

better namespsace of static functions


# 2bef11b8 15-Jan-2002 Warner Losh <imp@FreeBSD.org>

o Sync the device list with OLDCARD.
o Remove bogus flags that aren't used (if we need them in the future, we can
add them back).
o Add support for the TI-1031. This is the only YENTA compatible PCI-PCMCIA
bridge that I'm aware of (all the others are PCIC on a PCI bus, which is
different).


# 6015f069 13-Jan-2002 Warner Losh <imp@FreeBSD.org>

use bus_space(9) rather than the memory mapped register set. This is
the first step towrads merging pcic and pccbb for 16-bit cards.


# a432b68b 14-Dec-2001 Warner Losh <imp@FreeBSD.org>

Add support for suspending/resuming CardBus bridges.

We really should have and use power state information, but none exists
today.

Submitted by: YAMAMOTO Shigeru-san <shigeru@iij.ad.jp>


# 969c260d 26-Nov-2001 Warner Losh <imp@FreeBSD.org>

Make the start memory address that we use configurable via a boot
loader parameter. This allows us to more easily boot on big memory
configuration machines. hw.pccbb.start_mem. Reflect this in a sysctl
so we can read it from userland.

# Note: we need a TUNABLE_ULONG to do this right. I'll add that to
# kernel.h soon.


# 72905c7e 25-Nov-2001 Warner Losh <imp@FreeBSD.org>

style(9) fixes:
o declare variables at the start of the function, not the start of
a block.
o return (retval);
o minor {} tweaks.


# 746509ce 25-Nov-2001 Warner Losh <imp@FreeBSD.org>

peter pointed out that I missed a hard coded location for the memory.
Also add a define for I/O stuff (for cardbus).


# b772be11 25-Nov-2001 Warner Losh <imp@FreeBSD.org>

Make the address we kludily allocate in pccbb be a #define for easier
changing. Also change it from 0x44000000 to 0x84000000 for large memory
machines.

# the PCI bus code should do this for us. This is a bandaide, not a
# solution.


# 9d1efefd 03-Nov-2001 Poul-Henning Kamp <phk@FreeBSD.org>

Add PCIC_TI4410

(patch probably from imp@, can't remember figuring this out myself.)


# df6567b7 06-Sep-2001 Warner Losh <imp@FreeBSD.org>

minor commentary


# 9a253412 29-Aug-2001 Warner Losh <imp@FreeBSD.org>

First, The Ricoh 5C47x chips don't have the disable the 3e0 bits.
Second, the TI 1130 need to have the PCI_INTR set, not cleared.

This gets Soren's machine working with NEWCARD again.

# The whole initialization is a mess and needs to be organized ala OLDCARD.


# 472ce770 27-Aug-2001 Jonathan Chen <jon@FreeBSD.org>

Fix the hack that allocates memory when the bios haven't already done so.

We can't rely on rman to give us a useable memory window if we tell it to
do auto-allocation. This should probably be fixed on the pci bus/rman side.


# db3e3182 26-Aug-2001 Warner Losh <imp@FreeBSD.org>

Note difficulties we had in OLDCARD using NEWCARD's methods of debouncing card event interrupts.


# 63fa9f4c 26-Aug-2001 Jonathan Chen <jon@FreeBSD.org>

Part two of this NEWCARD update:

Briefly, the significant changes include:
* Way better resource management in pccbb, pccard and cardbus.
* pccard hot-removal now appears to work.
* support pre-fetchable memory in cardbus.
* update cardbus to support new pci bus interface functions.
* Fix CIS reading to no longer use rman_get_virtual().

What's not there, but in the works:
* pccard needs to do interrupt properly and not read the ISR on single
function cards.
* real resource management for pccard
* a complete implementation of CIS parsing
* need to look into how to correctly use mutex in pccbb


# 255b159f 26-Aug-2001 Jonathan Chen <jon@FreeBSD.org>

Non-functional changes to NEWCARD stuff.
This is the first part of a two-part update to NEWCARD. Changes in this
commit are non-functional, and includes the following:
* indentation and other changes to meet style(9).
* other minor style consistancy changes
* addition of comments
* renaming of device_t variables to be consistant across all of NEWCARD.

(note that not all style violations are fixed in this commit -- those that
aren't will be clobbered by the next commit.)


# 859c9099 29-Jun-2001 Warner Losh <imp@FreeBSD.org>

Fix warning message.

Suggested by: julian


# bd947818 20-Jun-2001 Warner Losh <imp@FreeBSD.org>

Revert last change: it was unintended at this time.


# 24236dfc 20-Jun-2001 Warner Losh <imp@FreeBSD.org>

Add new entries for:
TI1210, TI4410 and TI4450
and fix what looks like a typo in the OZ6860 entry.

Obtained from: NetBSD


# f4b56094 17-Apr-2001 Warner Losh <imp@FreeBSD.org>

Add some more O2Micro devices I gleened from the web site/linux pcmcia cs.
Add TI4451 as well.

These are untested since I don't have the hardware to test against.

Also, some O2Micro devices are #define w/o numbers as place holders so that
I can encourage people to submit them when they appear in the channels.


# 029f7392 17-Apr-2001 Warner Losh <imp@FreeBSD.org>

Add support for the OZ6832.

Submitted by: Martin Nilsson <martin@svenskabutiker.se>


# 80914f7e 11-Apr-2001 Warner Losh <imp@FreeBSD.org>

Add O2Micro's OZ6872 Cardbus bridge.

Submitted by: Robert Sexton <robert@kudra.com>


# a174ba72 30-Mar-2001 Jesper Skriver <jesper@FreeBSD.org>

Change the previous commit to be in style(9)

Reviewed by: jhb


# 6c00471f 29-Mar-2001 Jesper Skriver <jesper@FreeBSD.org>

Fix building NEWCARD again, by including
sys/types.h and sys/lock.h in pccbb.c, as
jhb noted in rev 1.12 of src/share/man/man9/mutex.9


# 9ed346ba 08-Feb-2001 Bosko Milekic <bmilekic@FreeBSD.org>

Change and clean the mutex lock interface.

mtx_enter(lock, type) becomes:

mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)

similarily, for releasing a lock, we now have:

mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.

The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.

Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:

MTX_QUIET and MTX_NOSWITCH

The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:

mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.

Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.

Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.

Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.

Finally, caught up to the interface changes in all sys code.

Contributors: jake, jhb, jasone (in no particular order)


# 11c0c4ae 08-Feb-2001 Warner Losh <imp@FreeBSD.org>

Fix memory leaks with dev_get_children().

Submitted by: Jeroen Ruigrok/Asmodai <asmodai@wxs.nl>


# 486d464d 07-Jan-2001 Warner Losh <imp@FreeBSD.org>

o Now that I've had time to test the new interface, reintegrate it back in.
o Fix OLDCARD to use the new interface.
o Rename the offsetp argument to deltap to more closely reflect what it
is returning (it returns the delta from the requested value to the actual
value).
o Remove duplicate $FreeBSD$ in pccbb.c
o Allow deltap to be NULL.
o Convert new isa pcic driver and add XXX comments that this function isn't
actually implemented there (which means that NEWCARD pccard stuff won't
work there until it is).
o Revert attempts to make old inferface work in NEWCARD.

Subitted by: peter (Parts of the new version code)


# 1bc96f7a 07-Jan-2001 Warner Losh <imp@FreeBSD.org>

Undo the interface change to CARD_GET_MEMORY_OFFSET. It wasn't tested
by even a compile of the OLDCARD code, was unapproved by me the keeper
of OLDCARD and broke OLDCARD and the ray driver.

Adjust new code to cope with the older interface.

If the interface changes in the future, it ***MUST*** be cleared by me
so that the OLDCARD impacts taken into account. It code in card_if.m
is used jointly by both OLDCARD and NEWCARD.


# 0c95c705 06-Jan-2001 Jonathan Chen <jon@FreeBSD.org>

* Better kld support in pccbb/cardbus
- pccbb no longer needs to remember whether a card is inserted.
- pccbb reissues insertion on load of cardbus/pccard modules.
- got rid of unnecessary delays in power functions.
- Cardbus children are no longer deleted if probe/attach fails.
- non-attached child devices are reprobed at driver_added.

* CARD interface to read CIS
- added card_cis_read/card_cis_free interface to read arbitrary CIS
data. This currently is only implemented in cardbus.

* pccard begins to work
- pccard can now use higher memory space (and uses it by default).
- set_memory_offset interface changed.
- fixed ccr access, which was broken at multiple locations.
- implement an interrupt handler - pccard can now share interrupts.
- resource alloc/release/activate/deactivate functions gutted: some
resources are allocated by the bridge before the child device is
probed or attached. Thus the resource "belongs" to the bridge, and
the pccard_*_resource functions need to fudge the owner/rid.
- changed some error conditions to panics to speed debugging.

* Mutex fix - Giant is entered at the beginning of thread


# 84c6b37d 12-Dec-2000 Mike Smith <msmith@FreeBSD.org>

Updates to match changes elsewhere in the PCI subsystem:

- Remove redundant header-type-specific support in the cardbus pcibus
clone. The bridges don't need this anymore.
- Use pcib_get_bus instead of the deprecated pci_get_secondarybus.
- Implement read/write ivar support for the pccbb, and teach it how
to report its secondary bus number. Save the subsidiary bus number
as well, although we don't use it yet.


# af82f62d 27-Nov-2000 Jonathan Chen <jon@FreeBSD.org>

A bunch of newcard/cardbus changes that's been sitting in my tree for a while:

- Make pccbb/cardbus kld loadable and unloadable.
- Make pccbb/cardbus use the power interface from pccard instead of inventing its own.
- some other minor fixes


# 283a9830 21-Oct-2000 Warner Losh <imp@FreeBSD.org>

Cleanup allocation of resources for 16-bits. We now do the right
thing in pccbb bridge (the pcic bridge will be updated as I merge the
two copies of the code that were in the original cardbus commit).


# f40ed9c2 20-Oct-2000 Warner Losh <imp@FreeBSD.org>

Allow interrupts to be sharable.

This allows us to probe, but not attach.


# b8493884 18-Oct-2000 Warner Losh <imp@FreeBSD.org>

Go ahead and disable the legacy mapping of the pcic registers on the
RF5C47x. Before the code would only do this on the RF5C46x bridges.

Submitted by: Jonathan Chen


# 0db7e66c 17-Oct-2000 Jonathan Chen <jon@FreeBSD.org>

Initial commit of NEWCARD cardbus side (that actually compiles and works)

Files:
dev/cardbus/cardbus.c
dev/cardbus/cardbusreg.h
dev/cardbus/cardbusvar.h
dev/cardbus/cardbus_cis.c
dev/cardbus/cardbus_cis.h
dev/pccbb/pccbb.c
dev/pccbb/pccbbreg.h
dev/pccbb/pccbbvar.h
dev/pccbb/pccbb_if.m

This should support:
- cardbus controllers:
* TI 113X
* TI 12XX
* TI 14XX
* Ricoh 47X
* Ricoh 46X
* ToPIC 95
* ToPIC 97
* ToPIC 100
* Cirrus Logic CLPD683x
- cardbus cards
* 3c575BT
* 3c575CT
* Xircom X3201 (includes IBM, Xircom and, Intel cards)
[ 3com support already in kernel, Xircom will be committed real soon now]

This doesn't work with 16bit pccards under NEWCARD.

Enable in your config by having "device pccbb" and "device cardbus".
(A "device pccard" will attach a pccard bus, but it means you system have
a high chance of panicing when a 16bit card is inserted)

It should be fairly simple to make a driver attach to cardbus under
NEWCARD -- simply add an entry for attaching to cardbus on a new
DRIVER_MODULE and add new device IDs as necessary. You should also make
sure the card can be detached nicely without the interrupt routine doing
something weird, like going into an infinite loop. Usually that should
entail adding an additional check when a pci register or the bus space is
read to check if it equals 0xffffffff.

Any problems, please let me know.

Reviewed by: imp