History log of /haiku/src/add-ons/kernel/drivers/disk/mmc/mmc_disk.cpp
Revision Date Author Comments
# 12bba381 05-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

nvme, mmc: Fix SMAP violations in B_GET_MEDIA_STATUS.

Fixes #18736.


# be67f14d 27-Apr-2023 Augustin Cavalier <waddlesplash@gmail.com>

mmc_disk: Refactor read/write/io hooks.

* Move geometry fetching to open(); it was not done
in io() and was duplicated in multiple places.

* Clean up clamping and bounds checking.

* Use IORequest::TransferredBytes().

Change-Id: I4157e516098dc0362c1478abd21a545c1f235cd7


# 215b685f 11-Dec-2022 X512 <danger_mail@list.ru>

kernel: Drop non-standard GNU inline assignment syntax

* We needed this previously due to our gcc2 compiled kernel.
* Now that our kernel is always latest gcc, we can move to the
c++20 syntax for inline assignment.
* Improves compatibility with clang, less GNU-specific stuff

Change-Id: Ib7272a0a52554a31e9a0e788fd3f031db9049795
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5898
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>


# 688acf41 15-Sep-2022 Jérôme Duval <jerome.duval@gmail.com>

add physical_block_size field where applicable

only scsi_disk checks the actual value, other drivers take the logical block size.

This change reports the physical block size from the disk rather than the block
size used by IDE/SATA/SCSI commands. On typical modern SATA disks, the SATA
commands will use 512 byte blocks, but the disk will actually read and write
4K blocks internally. This is only of importance for partition alignment for DriveSetup,
and is independant of file systems or partitioning systems. This could also influence
the recommended block size for some file systems.

Change-Id: Id0f2e22659e89fcef64c1f8d04f81cd68995e01f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5667
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>


# bd02d81c 30-Jun-2021 David Sebek <dasebek@gmail.com>

Fix trim-related issues

Fixes:
* Use uint64 instead of off_t when handling offset and size
of the trimmed range in the fs_trim_data structure
* BlockAllocator::Trim: Correct the size of a buffer
* ram_disk, mmc: Do not trim past device capacity

Improvements:
* BlockAllocator::Trim: Because the received offset and size
are ignored by BFS (the functionality is not implemented yet),
return B_UNSUPPORTED if the range does not cover the whole
partition
* ram_disk, mmc: More accurate calculation of the number
of trimmed bytes
* devfs: Add a uint64 version of translate_partition_access()

Change-Id: I24f4c08674f123ad33a5fef6e28996a4ada6ff0d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4155
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 2028d638 17-Jan-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

mmc_disk: implement B_TRIM_DEVICE

Change-Id: Ib08a1e196441f35550fe221b912332b4803a04b4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3641
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 5ec64c5c 16-Jan-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

sd/mmc: Cleanup and improve reliability

Store the bus cookie in the mmc_disk driver and pass it to the bus
manager when executing commands. This avoids calling into the device
manager at each read and write operation. The code to get the cookie
from mmc_disk isn't so nice since it needs to access the grandparent
device (the mmc bus root), it would be simpler if this cookie would be
available directly from mmc bus devices.

We can get card removal and card insertion interrupt at the same time
due to insufficient hardware debouncing (the SDHCI spec says we
shouldn't, but it happens on Ricoh controllers. Can't blame them, they
don't advertise themselves as compliant with the spec). So, check the
card status from the interrupt handler and ignore the incorrect
interrupts.

Fix unreliable card initialization: power must be turned on before
starting up the SD clock. Remove a now unneeded delay that was added in
an attempt to avoid initial instability.

Change-Id: Ibd8d051da1a1d859f3924ee535f4a05d9b6398d4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3639
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 34552f8e 14-Jan-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

sd/mmc: enable 4-bit data transfers

It works, but performance is still unexpectedly low (getting about
50kB/s write speed) with almost no CPU load.

Change-Id: I7da3ee70c8b379c4e6c2250d67f880c78635874f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3630
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 2aa5a035 12-Jan-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

mmc_disk: disable currently non working code

Switching to 4 bit mode requires some more coordination as the host
controller must also be switched, right after sending this command.

I will revisit this, but the previous commit was accidentally pushed to
master.

At least we get the 25MHz clock instead of 400kHz, that should already
be quite a performance improvement.


# 522c141d 12-Jan-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

[WIP] sd/mmc: enable high speed transfers

- Switch to 25MHz clock
- Switch to 4bit transfers mode (the default is 1bit)

Reading and writing SD cards do not seem to work anymore with these
changes. I get invalid data on read, and on write, an interrupt is never
called in some cases.


# 24136793 08-Jan-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

sdhci_pci: support for inserting cards after boot.

Change-Id: Ic67ea38bb80b35528ebb1a150d1a916a56184e69
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3617
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# d1fee57d 15-Dec-2020 Adrien Destugues <adrien.destugues@opensource.viveris.fr>

mmc_disk: add SDHC support.

The main differences:
- The initialization sequence requires an additional command (this was
already done)
- The layout of the CSD register and the way to compute the device
geometry from it changes
- The read and write commands parameter is a sector number instead of a
byte position

Change-Id: Ie729e333c9748f36b37acd70c970adfd425cf0b6
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3512
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# e21a1abe 13-Dec-2020 Adrien Destugues <adrien.destugues@opensource.viveris.fr>

mmc: properly set DMA restrictions

- The restrictions are now set by the sdhci bus and retrieved from there
by the DMAResources.
- Configure SDMA with the maximal available boundary check of 512K and
publish the corresponding DMA restrictions.
- dma_resource cannot be initialized implicitly as a member of
mmc_disk_driver_info because mmc_disk_driver_info is allocated with
malloc/free, not new/delete. So we now explicitly allocate and delete
it.

This allows reads and writes of more than a single block at a time.

Change-Id: Ibb97c91543312c7970c28a7a8c68a12708263e32
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3505
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# 9a37366b 12-Dec-2020 Adrien Destugues <adrien.destugues@opensource.viveris.fr>

mmc_disk: add write support

Change-Id: I77cf1612569c43e79917ac5a1493b7ab4a04cb47
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3504
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# 7a160a86 06-Dec-2020 Adrien Destugues <adrien.destugues@opensource.viveris.fr>

mmc_disk: read using "simple DMA"

The SDHCI spec also offers an "advanced DMA" mode where we can use
scatter-gather lists. It would allow to remove several of the DMA
restrictions, but hardware support for it is optional, so we need this
version anyway.

The geometry is retrieved on demand in the first read or write or in a
call to the get geometry or get device size ioctl. It is not possible to
retrieve it from the device initialization because that is called as
part of the mmc_bus scanning, which needs a specific sequence of
commands and keeps the bus locked to prevent drivers to insert their own
commands in the middle of that sequence.

TODO:
- Move the DMA restrictions definition to sdhci_pci and forward it up to
mmc_disk (which is the one creating the IOScheduler)
- Decide if we want to keep non-DMA support (probably should, but it
makes things more complex, because it uses virtual addresses)

Change-Id: Ib1dd14eacf62052d747bfb3ef7820bc5a34d3030
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3471
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# 74b60970 14-Oct-2020 Anarchos <sylvain_kerjean@hotmail.com>

sd/mmc: read, naive method

First implementation of reading sectors from an SD card.
This is not the best performance for many reasons:
- No DMA
- Reads only one sector at a time
- Cannot read more than 512 bytes per syscall

Also there are major limitations:
- Cannot read less than 512 bytes. The hardware of course works in full
sectors. The mmc_disk driver should go through the io scheduler to
make sure requests have a reasonable size and offset, and nothing
tries to read just a few bytes in the middle of a sector.
- SD cards only (no SDHC, no MMC)

Architecture problems:
I think too much of the implementation is done in sdhci_pci and should
be moved to the upper layers. However it is difficult to say without
having implemented DMA (which indeed will be at the low level of the
sdhci controller). It doesn't help that the order of operations is a
bit different depending on wether there is DMA or not. In DMA mode you
first prepare the buffer, then run the command. In non-DMA mode you
first send the command, then read the data into the buffer. We need an
API at the mmc_bus level that doesn't care about that low-level detail.
There are other things that the MMC bus should be doing however, such
as switching to different clock speeds depending on which card is
activated and how fast it can go.

At least the following should be done:
- The read method for mmc_bus and sdhci_pci should use a scatter-gather
structure as a parameter instead of a single buffer
- See if can be integrated into ExecuteCommand at sdhci level (it's
essentially a command with an additional data phase)

Change-Id: I688b6c694561074535c9c0c2545f06dc04b06e7d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3466
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# eb92a834 26-Jul-2020 Adrien Destugues <adrien.destugues@opensource.viveris.fr>

sd/mmc: fix warnings

Change-Id: I5d0c95240cd5594b0f8090f5ec7b3f6ee181dacc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3464
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# e4689893 19-Feb-2019 Adrien Destugues <pulkomandy@pulkomandy.tk>

Initial work for the mmc_disk driver

No read and write support for now. But we implement getting SD card
capacity. SDHC is not supported yet (it uses a different layout for the
CSD register which will be rejected by this version of the code)

Change-Id: Ife844a62f3846c0a780259e9a3a08195e2fd965e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1068
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 25b6a6f1 28-Apr-2018 krish_iyer <krishnaniyer97@gmail.com>

SDHCI MMC Driver

1. SDHCI PCI Bus: Discovering SDHC device from the PCI bus
and registers a child node(MMC bus) to which slots
are attached. SDHC registers are mapped by MMUIO,
they are binded in a structure(struct* registers).
A pin based interrupt handler is also installed,
which triggers the handler function and interrupts
are being taken care of. Added API's to set-up and
the clock for SD/MMC card, change frequency and
reset the registers.

2. Device Manager: Currently, busses subdir lists are har-
dcoded and in order to load the driver. We hard
coded the bus dir under PCI devices.

3. MMC Disk Driver: In order to register the slots under
/dev/disk/mmc and hence data transfer and other
operations can be done.

4. MMC Bus Manager: Setted up a bus manager to create an object
to do a particular for eg certain data transfer and
get freed until another operation is requested.

Change-Id: I369354da6b79adc6b6dfb08fe160334af1392a34
Reviewed-on: https://review.haiku-os.org/318
Reviewed-by: Alexander von Gluck IV <kallisti5@unixzen.com>