Commit graph

97 commits

Author SHA1 Message Date
Emmanuel Vadot be82b3a0bf clk: Move clock code in dev/clk
We've removed kernel option EXT_RESOURCES almost two years ago.
While it was ok to have some code under a common 'extres' subdirectory
at first, we now have a lot of consumer of it and we made it mandatory
so no need to have it under a cryptic name.

Reviewed by:	mhorne
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D43191
2024-01-10 19:20:26 +01:00
Warner Losh fdafd315ad 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
2023-11-26 22:24:00 -07:00
Warner Losh 031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Warner Losh 4d846d260e 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
2023-05-12 10:44:03 -06:00
Stephen J. Kiernan 76735c7439 flash: Add "n25q64" to mx25l driver
This is for 64Mb Micron N25Q serial NOR flash memory

Obtained from:	Juniper Networks, Inc.
2023-04-18 00:21:17 -04:00
John Baldwin 0d95fe04c6 spi flash: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 12:22:04 -07:00
John Baldwin ead64e8454 flash: Remove unused variables. 2022-04-13 16:08:22 -07:00
Warner Losh 20669405d2 flexspi: In flex_spi_task remove dev, it's write only
Sponsored by:		Netflix
2022-04-05 21:42:05 -06:00
Warner Losh edcced8ab7 mx25l_task: eliminate dev write only variable
Sponsored by:		Netflix
2022-04-04 22:29:29 -06:00
Kornel Duleba 43c4b47b75 flex_spi: Don't try to destroy disk if it doesn't exist
Try to stop and destroy the dist only if the driver has been successfully
attached. Otherwise a kernel panic will be triggered from disk_destroy.
The issue was observed on a board that missed SPI clock description in DT.
2021-12-07 07:13:53 +01:00
Wojciech Macek 94e25b7acb flex_spi: Support for FlexSPI Flash controller.
NXP FlexSPI is a complex SPI controller which provides
full offload for accessing NOR Flash.
Create a Flash driver which attaches to existing FreeBSD
infrastructure and exports generic READ and WRITE disk commands.
The Flash has to be identified first to configure controller
internals. For now, only one NOR Flash chip is supported.
Future commits shall either increase number of known chips
or implement SFDP mechanism which can be used by other Flash
drivers.

Sponsored by:		Alstom
Obtained from:		Semihalf
Differential revision:	https://reviews.freebsd.org/D33117
2021-11-30 06:41:34 +01:00
Thomas Skibo 416ac155bb mx25l: Add support for Integrated Silicon Solution is25wp256
This is used for the on-board flash on the HiFive Unmatched board.

Reviewed by:	#riscv, jrtc27
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D31562
2021-08-30 23:38:02 +01:00
Konstantin Belousov cd85379104 Make MAXPHYS tunable. Bump MAXPHYS to 1M.
Replace MAXPHYS by runtime variable maxphys. It is initialized from
MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys.

Make b_pages[] array in struct buf flexible.  Size b_pages[] for buffer
cache buffers exactly to atop(maxbcachebuf) (currently it is sized to
atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1.
The +1 for pbufs allow several pbuf consumers, among them vmapbuf(),
to use unaligned buffers still sized to maxphys, esp. when such
buffers come from userspace (*).  Overall, we save significant amount
of otherwise wasted memory in b_pages[] for buffer cache buffers,
while bumping MAXPHYS to desired high value.

Eliminate all direct uses of the MAXPHYS constant in kernel and driver
sources, except a place which initialize maxphys.  Some random (and
arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted
straight.  Some drivers, which use MAXPHYS to size embeded structures,
get private MAXPHYS-like constant; their convertion is out of scope
for this work.

Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs,
dev/siis, where either submitted by, or based on changes by mav.

Suggested by: mav (*)
Reviewed by:	imp, mav, imp, mckusick, scottl (intermediate versions)
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D27225
2020-11-28 12:12:51 +00:00
Nick O'Brien 3f59a7f97b flash: Add support for SPI flash s25fl512s
Reviewed by:	kp
Approved by:	kp (mentor)
Sponsored by:	Axiado
2020-10-02 17:33:56 +00:00
Ruslan Bukin d987842d1e Enter the network epoch in the xdma interrupt handler if required
by a peripheral device driver.

Sponsored by:	DARPA, AFRL
2020-02-08 23:07:29 +00:00
Scott Long d176b8039e Ever since the block layer expanded its command syntax beyond just
BIO_READ and BIO_WRITE, we've handled this expanded syntax poorly in
drivers when the driver doesn't support a particular command.  Do a
sweep and fix that.

Reported by:	imp
2020-02-07 09:22:08 +00:00
Emmanuel Vadot 2de9b4d347 zilinx/zy7_qspi: Add a qspi driver for Zynq platforms.
This is a qspi driver for the Xilinx Zynq-7000 chip.
It could be useful for anyone wanting to boot a system from flash memory
instead of SD cards.

Submitted by:	Thomas Skibo (thomasskibo@yahoo.com)
Differential Revision:	https://reviews.freebsd.org/D14698
2020-01-19 20:04:44 +00:00
Ian Lepore e2448a8112 Explicitly include sys/rman.h instead of relying on getting it via some
other header.
2020-01-02 22:14:44 +00:00
Warner Losh f86e60008b 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.
2019-12-04 16:56:11 +00:00
Emmanuel Vadot d1ecd3ac13 flash: Add GigaDevice gd25q128 flash
Add this flash chip which is a 128Mb spi flash.

MFC after:	1 week
2019-10-25 17:56:24 +00:00
Ian Lepore db63d25160 Use the new FDTCOMPAT_PNP_INFO() macro to define SPIBUS_FDT_PNP_INFO().
Also rename SPIBUS_PNP_INFO -> SPIBUS_FDT_PNP_INFO because there could be
other kinds of pnpinfo for other (non-fdt) bus attachments.
2019-05-23 15:59:50 +00:00
Ian Lepore 68dd779577 Give the mx25l device sole ownership of the name /dev/flash/spi* instead of
trying to use disk_add_alias() to make spi* an alias for mx25l*.  It turns
out disk_add_alias() works for partitions, but not slices, and that's hard
to fix.

This change is, in effect, a partial revert of r344526.

The mips world relies on the existence of flashmap names formatted as
/dev/flash/spi0s.name, whereas pretty much nothing relies on at45d devices
using the /dev/spi* names (because until recently the at45d driver didn't
even work reliably). So this change makes mx25l devices the sole owner of
the /dev/flash/spi* namespace, which actually makes some sense because it is
a SpiFlash(tm) device, so flash/spi isn't a horrible name.

Reported by:	Mori Hiroki <yamori813@yahoo.co.jp>
2019-03-10 18:48:08 +00:00
Ian Lepore e70ece1297 Allow the sector size of the disk device to be configured using hints or
FDT data.  The sector size must be a multiple of the device's page size.
If not configured, use the historical default of the device page size.

Setting the disk sector size to 512 or 4096 allows a variety of standard
filesystems to be used on the device.  Of course you wouldn't want to be
writing frequently to a SPI flash chip like it was a disk drive, but for
data that gets written once (or rarely) and read often, using a standard
filesystem is a nice convenient thing.
2019-03-02 23:20:47 +00:00
Ian Lepore 2274a2f725 Add some comments. Give #define'd names to some scattered numbers. Change
some #define'd names to be more descriptive.  When reporting a post-write
compare failure, report the page number, not the byte address of the page.
The latter is the only functional change, it makes the number match the
words of the error message.
2019-03-02 22:28:43 +00:00
Ian Lepore d4249d08d9 Bugfix: use a dummy buffer for the inactive side of a transfer.
This is especially important for writes.  SPI is inherently a bidirectional
bus; you receive data (even if it's garbage) while writing.  We should not
receive that data into the same buffer we're writing to the device.

When reading it doesn't matter what we send to the device, but using the
dummy buffer for that as well is pleasingly symmetrical.
2019-03-02 20:58:51 +00:00
Ian Lepore 33ec975b20 Add a module dependency on fdt_slicer. Also, move the PNP_INFO to its more
usual location, down near the DRIVER_MODULE() stuff.
2019-02-26 22:52:41 +00:00
Ian Lepore fb4f7d70c1 Add a module dependency on fdt_slicer. 2019-02-26 22:52:08 +00:00
Ian Lepore fb01947189 Add support for geom_flashmap by providing a getattr() for "SPI:device". 2019-02-26 20:50:49 +00:00
Ian Lepore dec1d3370d Fix a paste-o that broke the build on all arches.
Reported by:	many
Pointy hat:	ian@
2019-02-25 18:11:59 +00:00
Ian Lepore d3248c4170 Resolve a name conflict when both SpiFlash and DataFlash devices are present.
Both SpiFlash (mx25l) and DataFlash (at45d) drivers create a disk device
with a name of /dev/flash/spiN where N is the driver's unit number.  If
both types of devices are present in the same system, this creates a fatal
conflict that prevents attachment of whichever device attaches second
(because mx25l0 and at45d0 both try to create a spi0).

This gives each type of device a unique name (mx25lN or at45dN respectively)
and also adds an alias of spiN for compatibility.  When both device types
appear in the same system, only the first to attach gets the spiN alias.
When the second device attaches there is a non-fatal warning that the alias
can't be created, but both devices are still accessible via their primary
names (and there is no need for the spiN name to work for backwards
compatibility on such a system, because it has never been possible to use
the spiN names when both devices exist).
2019-02-25 17:30:01 +00:00
Ian Lepore 56e07c3e97 Add a metadata entry for the AT45DB641E chip. This chip has the same 3-byte
jedec ID as its older cousin the AT45DB642D, but uses a different page size.
The only way to distinguish between the two chips is that the 2D chip has
0 bytes of extended ID info and the new 1E has 1 byte of extended ID.  The
actual value of the extended ID byte is all zeroes.  In other words, it's
the presence of the extended info that identifies this chip. (Presumably
a future upgrade might define non-zero values for the extended ID byte.)
2019-02-25 16:40:10 +00:00
Ian Lepore 9b9a1641a6 Include the jedec "extended device information string" in the criteria used
to match a chip to our table of metadata describing the chips. At least one
new DataFlash chip has a 3-byte jedec ID identical to its predecessors and
differs only in the extended info, and it has different metadata requiring a
unique entry in the table.  This paves the way for supporting such chips.

The metadata table now includes two new fields, extmask and extid.  The two
bytes of extended info obtained from the chip are ANDed with extmask then
compared to extid, so it's possible to use only a subset of the extended
info in the matching.

We now always read 6 bytes of jedec ID info. Most chips don't return any
extended info, and the values read back for those two bytes may be
indeterminate, but such chips have extmask and extid values of 0x0000 in the
table, so the extid effectively doesn't participate in the matching on those
chips and it doesn't matter what they return in the extended info bytes.
2019-02-25 16:20:58 +00:00
Ian Lepore 3ea8b6b327 Switch to using config_intrhook_oneshot(). That allows the error handling
in the delayed attach to use early returns, which allows reducing the level
of indentation.  So all in all, what looks like a lot of changes is really
no change in behavior, mostly just moving whitespace around.
2019-02-25 03:29:12 +00:00
Ian Lepore b9f8045598 Add support for probing/attaching on FDT-based systems. 2019-02-24 23:16:33 +00:00
Ian Lepore 4b06839fbf Add a functional detach() implementation to make module unloading possible. 2019-02-24 23:08:53 +00:00
Warner Losh d3f1313287 Remove All Rights Reserved
Remove the all rights reserved clause from my copyright, and make
other minor tweaks needed where that might have created ambiguity.
2019-02-05 21:37:34 +00:00
Ian Lepore 6dfd050075 The device ID tables are used only within the driver, make them static so
that both of these drivers can exist in the same kernel.
2018-07-29 16:55:28 +00:00
Emmanuel Vadot 7de871aa81 mx25l: compat_data is only defined when FDT is
Reported by:	O. Hartmann <ohartmann@walstatt.org>
2018-06-14 19:01:40 +00:00
Emmanuel Vadot 50d3578f0b mx25l: Add pnp info 2018-06-14 17:21:09 +00:00
Emmanuel Vadot bb5125a411 mx25l: Add mx25l1606e
This is a 16Mbits spi flash arranged in 32x64k blocks or 512x4k
sectors.
2018-05-17 10:13:18 +00:00
Ruslan Bukin eb69ed7f87 Add driver for Cadence Quad SPI Flash Controller found on
Intel® Arria® 10 SoC.

Cadence Quad SPI Flash is not generic SPI controller, but SPI flash
controller, so don't use spibus here, instead provide quad spi flash
interface.

Since it is not on spibus, then mx25l flash device driver is not usable
here, so provide new n25q flash device driver with quad spi flash
interface.

Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D10245
2018-04-23 10:35:00 +00:00
Ian Lepore d892051323 Add the device/chip type to the disk d_descr field, and print more info
about the chip including the erase block size at attach time.

Also add myself to the copyrights since at this point svn blame would point
to me as the culprit for much of this.
2018-03-18 18:58:47 +00:00
Ian Lepore 3c9af13c75 Add support for 4K and 32K erase block sizes. Many of the supported chips
have these flags set in the ident table, but there was no code to support
using the smaller erase sizes.
2018-03-18 18:37:47 +00:00
Ian Lepore c03ab159f6 Make all internal routines return an int error status, and check the
status at all call points.  Combine the get_status and wait_for_ready
routines, since waiting for ready is the only reason to ever get status.
2018-03-18 17:47:57 +00:00
Ian Lepore 89a1585b8d Add sc_parent to the softc and use it in place of device_get_parent() calls
all over the place.  Also pass the softc as the arg to all the internal
functions instead of passing a device_t and calling device_get_softc() in
each function.
2018-03-18 17:25:23 +00:00
Ian Lepore 89a895b63c Bugfix: wait for writes/erases to complete after starting them, instead of
before starting them.

Using the wait-before logic would make sense if there was useful time-
consuming work that could be done between the end of one write and the
beginning of the next, but it also requires doing the wait-for-ready before
reading, because a prior write or erase could still be in progress.  Reading
is the far more common case, so adding a whole extra bus transaction to
check for ready before each read would soak up any small gains that might be
had from doing async writes.
2018-03-18 16:52:31 +00:00
Ian Lepore 19aa9f7183 Eliminate some unneeded intermediate variables. Eliminate some redundant
parens in shift-and-mask expressions.  Reword and reflow some comments.
2018-03-18 16:36:14 +00:00
Ian Lepore f432eb7ea1 Remove a pointless KASSERT and reword a comment a bit. The KASSERT tested
for the same condition that the preceeding lines checked for and would have
returned EIO, so the assert could never possibly trigger (sc_sectorsize must
inherently be an integer multiple of FLASH_PAGE_SIZE).
2018-03-18 16:10:14 +00:00