Add the I3C subsystem
Subsystems (6)
v9 cover Add the I3C subsystem
Hi Greg,
I think we've reached a point where we can eventually consider the I3C framework for inclusion in 4.20 (5.0?). Indeed, v8 has received a R-b from Arnd, and I addressed the concerned raised by Joe on the I3C/I2C_DEV() macros. I hope to get an Ack from Rob on the adjusted DT bindings anytime soon.
The only remaining concern raised by Arnd is the fact that both hosts and slaves share the same bus type and are differentiated thanks to their device_type, which IMHO is fine since this is what other subsystems do (plus I don't see other solutions to have both I3C devices and I3C buses represented under /sys/bus/i3c/).
I'd really like to get this series merged in 4.20 so that other contributors can work on top of that to add
1/ new host drivers
2/ support for advanced features
3/ new device drivers
So, unless you have strong reasons to reject this request, and, assuming I get Rob's ack soon enough, I plan to send a PR for this framework next week.
Here is the usual description copy&pasted from the previous versions:
This patch series is adding a new subsystem to support I3C devices.
This is just adding support for basic features. Extra features will be added afterwards.
There are a few design choices that are worth mentioning because they impact the way I3C device drivers can interact with their devices:
- all functions used to send I3C/I2C frames must be called in non-atomic context. Mainly done this way to ease implementation, but this is still open to discussion. Please let me know if you think it's worth considering an asynchronous model here
- the I3C bus and I3C master controller are now tightly coupled even though they're still allocated separately. There's now a 1:1 relationship between these objects, and the I3C master is no longer represented under the I3C bus object.
Arnd, let me know if you had something different in mind, and I'll rework the implementation accordingly.
- I2C backward compatibility has been designed to be transparent to I2C drivers and the I2C subsystem. The I3C master just registers an I2C adapter which creates a new I2C bus. I'd say that, from a representation PoV it's not ideal because what should appear as a single I3C bus exposing I3C and I2C devices here appears as 2 different busses connected to each other through the parenting (the I3C master is the parent of the I2C and I3C busses).
On the other hand, I don't see a better solution if we want something that is not invasive.
Missing features (will be added in separate patch series after initial support has been accepted/merged):
- support for HDR modes (has been removed because of lack of real users)
- no support for multi-master and the associated concepts (mastership handover, support for secondary masters, ...)
- I2C devices can only be described using DT because this is the only use case I have. However, the framework can easily be extended with ACPI and board info support
- I3C slave framework. This has been completely omitted, but shouldn't have a huge impact on the I3C framework because I3C slaves don't see the whole bus, it's only about handling master requests and generating IBIs. Some of the struct, constant and enum definitions could be shared, but most of the I3C slave framework logic will be different
Note that this patchset is available on the linux-i3c repo[1].
Main change between v8 and v9:
- The DT bindings have been simplified to get rid of the I3C/I3C_DEV() macros
Main change between v7 and v8:
- The bus object is now embedded in the master_controller object (as suggested by Arnd)
Main changes between v6 and v7:
- I3C bus/master representations have been reworked to match what other subsystems are doing (master implicitly represented by the bus object)
- I3C dev registration has been fixed
- I3C bus mode selection has been fixed
- Calls to readsl/writesl() in the Cadence I3C master driver have been fixed
Main changes between v5 and v6:
- Introduce {i3c,i2c}_dev_desc structures to better match how I3C master controllers (reservation of one HW slot for each device attached to the bus). With this solution, the resource migration that happens when a device lose its dynamic address and is re-assigned a different address is simplified on the driver side, because most of it is now handled in the core (reserve a new dev slot, reserve IBI resources and free all resources attached to the old slot)
- Add I3C error codes (M0 to M2) so that the core and device drivers can have fine grained information on what caused an EIO error.
Only minor things happened between v3 and v5 (you can go check the changelog in each patch for more details).
Main changes between v2 and v3 are:
- Reworked the DT bindings as suggested by Rob
- Reworked the bus initialization step as suggested by Vitor
- Added a driver for an I3C GPIO expander
Main changes between the initial RFC and this v2 are:
- Add a generic infrastructure to support IBIs. It's worth mentioning that I tried exposing IBIs as a regular IRQs, but after several attempts and a discussion with Mark Zyngier, it appeared that it was not really fitting in the Linux IRQ model (the fact that you have payload attached to IBIs, the fact that most of the time an IBI will generate a transfer on the bus which has to be done in an atomic context, ...)
The counterpart of this decision is the latency induced by the workqueue approach, but since I don't have real use cases, I don't know if this can be a problem or not.
- Add helpers to support Hot Join
- Add support for IBIs and Hot Join in Cadence I3C master driver
- Address several issues in how I was using the device model
Thanks,
Boris
[1]https://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux.git/log/?h=i3c/next
Boris Brezillon (9):
i3c: Add core I3C infrastructure
docs: driver-api: Add I3C documentation
i3c: Add sysfs ABI spec
dt-bindings: i3c: Document core bindings
MAINTAINERS: Add myself as the I3C subsystem maintainer
i3c: master: Add driver for Cadence IP
dt-bindings: i3c: Document Cadence I3C master bindings
gpio: Add a driver for Cadence I3C GPIO expander
dt-bindings: gpio: Add bindings for Cadence I3C gpio expander
Documentation/ABI/testing/sysfs-bus-i3c | 146 + .../bindings/gpio/gpio-cdns-i3c.txt | 39 + .../bindings/i3c/cdns,i3c-master.txt | 44 + Documentation/devicetree/bindings/i3c/i3c.txt | 138 + .../driver-api/i3c/device-driver-api.rst | 9 + Documentation/driver-api/i3c/index.rst | 11 + .../driver-api/i3c/master-driver-api.rst | 10 + Documentation/driver-api/i3c/protocol.rst | 203 ++ Documentation/driver-api/index.rst | 1 + MAINTAINERS | 12 + drivers/Kconfig | 2 + drivers/Makefile | 2 +- drivers/gpio/Kconfig | 11 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-cdns-i3c.c | 411 +++ drivers/i3c/Kconfig | 24 + drivers/i3c/Makefile | 4 + drivers/i3c/device.c | 233 ++ drivers/i3c/internals.h | 26 + drivers/i3c/master.c | 2648 +++++++++++++++++ drivers/i3c/master/Kconfig | 6 + drivers/i3c/master/Makefile | 1 + drivers/i3c/master/i3c-master-cdns.c | 1671 +++++++++++ include/linux/i3c/ccc.h | 385 +++ include/linux/i3c/device.h | 331 +++ include/linux/i3c/master.h | 643 ++++ include/linux/mod_devicetable.h | 17 + 27 files changed, 7028 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-i3c create mode 100644 Documentation/devicetree/bindings/gpio/gpio-cdns-i3c.txt create mode 100644 Documentation/devicetree/bindings/i3c/cdns,i3c-master.txt create mode 100644 Documentation/devicetree/bindings/i3c/i3c.txt create mode 100644 Documentation/driver-api/i3c/device-driver-api.rst create mode 100644 Documentation/driver-api/i3c/index.rst create mode 100644 Documentation/driver-api/i3c/master-driver-api.rst create mode 100644 Documentation/driver-api/i3c/protocol.rst create mode 100644 drivers/gpio/gpio-cdns-i3c.c create mode 100644 drivers/i3c/Kconfig create mode 100644 drivers/i3c/Makefile create mode 100644 drivers/i3c/device.c create mode 100644 drivers/i3c/internals.h create mode 100644 drivers/i3c/master.c create mode 100644 drivers/i3c/master/Kconfig create mode 100644 drivers/i3c/master/Makefile create mode 100644 drivers/i3c/master/i3c-master-cdns.c create mode 100644 include/linux/i3c/ccc.h create mode 100644 include/linux/i3c/device.h create mode 100644 include/linux/i3c/master.h
Signature · 1 line
2.17.1
PATCH v9 1/9 i3c: Add core I3C infrastructure
Add core infrastructure to support I3C in Linux and document it.
This infrastructure adds basic I3C support. Advanced features will be added afterwards.
There are a few design choices that are worth mentioning because they impact the way I3C device drivers can interact with their devices:
- all functions used to send I3C/I2C frames must be called in non-atomic context. Mainly done this way to ease implementation, but this is not set in stone, and if anyone needs async support, new functions can be added later on.
- the bus element is a separate object, but it's tightly coupled with the master object. We thus have a 1:1 relationship between i3c_bus and i3c_master_controller objects, and if 2 master controllers are connected to the same bus and both exposed to the same Linux instance they will appear as two distinct busses, and devices on this bus will be exposed twice.
- I2C backward compatibility has been designed to be transparent to I2C drivers and the I2C subsystem. The I3C master just registers an I2C adapter which creates a new I2C bus. I'd say that, from a representation PoV it's not ideal because what should appear as a single I3C bus exposing I3C and I2C devices here appears as 2 different buses connected to each other through the parenting (the I3C master is the parent of the I2C and I3C busses).
On the other hand, I don't see a better solution if we want something that is not invasive.
Missing features:
- I3C HDR modes are not supported
- no support for multi-master and the associated concepts (mastership handover, support for secondary masters, ...)
- I2C devices can only be described using DT because this is the only use case I have. However, the framework can easily be extended with ACPI and board info support
- I3C slave framework. This has been completely omitted, but shouldn't have a huge impact on the I3C framework because I3C slaves don't see the whole bus, it's only about handling master requests and generating IBIs. Some of the struct, constant and enum definitions could be shared, but most of the I3C slave framework logic will be different
---
Changes in v9:
- Modify the DT parsing code to match the reg encoding
- Add Arnd's R-b
Changes in v8:
- Embed the i3c_bus object directly in the i3c_master_controller one (suggested by Arnd)
- Move core.c into master.c (suggested by Arnd)
- Replace bool by unsigned int (or u8) in structures (suggested by checkpatch)
Changes in v7:
- Stop representing the I3C master as a device under the I3C bus
- Enforce a 1:1 relationship between i3c_bus and i3c_master_controller objects
- Fix I3C bus mode selection when I2C devices are described in the DT.
- Fix I3C device registration
Changes in v6:
- Add I3C/I2C dev descriptors to simplify I3C driver controllers when migrating resources from on I3C device slot to anoter
- Add I3C error codes and return them when doing SDR/priv and CCC transfers. This allows us to properly detect when no devices acked a CCC command, which in some cases is a valid situation (no I3C devices on the bus)
- Remove __packed specifiers where unneeded
- Allocate all IBI slots in one call using kcalloc()
Changes in v5:
- Rename the address sysfs entry into dynamic_address to clarify things
- Document that we expect buffers passed to i3c_device_do_priv_xfers() to be DMA-able
- Fix DEFSLVS CCC command
- s/2017/2018/ in copyright headers
- Fix SPDX header in internals.h
- Fix coding style issues
Changes in v4:
- none
Changes in v3:
- Fix locking issues
- Explicitly include a bunch of headers (reported by Randy Dunlap)
- Rename {i2c,i3c}-scl-frequency DT prop into {i2c,i3c}-scl-hz
- Do not use BIT() macro in mod_devicetable.h
- Fix typos
- Fix/enhance some kernel doc headers
- Rework the bus initialization code to simplify master drivers
- Assign dynamic address with SETDASA if the device has a static address and the DT has a valid assigned-address property
- Rework the LVR extraction in DT parsing code
- Add code to detect when a device is re-attached to the bus after losing its dynamic address. In this case we know try to re-assign the old address, and most importantly, the I3C device driver sees the same device instance, not a new one
- Add an ->i2c_funcs() hook to let the master declare which I2C features it supports
- Unexport a few functions
- Remove support for HDR mode since we have no real user yet
Changes in v2:
- Fix a bunch of mistake I made with the device model (pointed by GKH)
- Move the documentation out of this commit (pointed by GKH)
- only source drivers/i3c/master/Kconfig when CONFIG_I3C is enabled (pointed by GKH)
- Add IBI infrastructure
- Add helpers to ease support for Hot Join (most of the logic is delegated to I3C controller drivers)
- move the doc out of this commit to improve readability
- Fix a few bugs in device probing/remove (detected after trying to load/unload modules in various orders)
- Add a module_i3c_i2c_driver() macro to ease integration of drivers for devices that support both I3C and I2C mode
--- drivers/Kconfig | 2 + drivers/Makefile | 2 +- drivers/i3c/Kconfig | 24 + drivers/i3c/Makefile | 4 + drivers/i3c/device.c | 233 +++ drivers/i3c/internals.h | 26 + drivers/i3c/master.c | 2648 +++++++++++++++++++++++++++++++ drivers/i3c/master/Kconfig | 0 drivers/i3c/master/Makefile | 0 include/linux/i3c/ccc.h | 385 +++++ include/linux/i3c/device.h | 331 ++++ include/linux/i3c/master.h | 643 ++++++++ include/linux/mod_devicetable.h | 17 + 13 files changed, 4314 insertions(+), 1 deletion(-) create mode 100644 drivers/i3c/Kconfig create mode 100644 drivers/i3c/Makefile create mode 100644 drivers/i3c/device.c create mode 100644 drivers/i3c/internals.h create mode 100644 drivers/i3c/master.c create mode 100644 drivers/i3c/master/Kconfig create mode 100644 drivers/i3c/master/Makefile create mode 100644 include/linux/i3c/ccc.h create mode 100644 include/linux/i3c/device.h create mode 100644 include/linux/i3c/master.h
drivers/Kconfig +2 -0
@@ -57,6 +57,8 @@ source "drivers/char/Kconfig" source "drivers/i2c/Kconfig" +source "drivers/i3c/Kconfig" + source "drivers/spi/Kconfig" source "drivers/spmi/Kconfig"
drivers/Makefile +1 -1
@@ -111,7 +111,7 @@ obj-$(CONFIG_SERIO) += input/serio/ obj-$(CONFIG_GAMEPORT) += input/gameport/ obj-$(CONFIG_INPUT) += input/ obj-$(CONFIG_RTC_LIB) += rtc/ -obj-y += i2c/ media/ +obj-y += i2c/ i3c/ media/ obj-$(CONFIG_PPS) += pps/ obj-y += ptp/ obj-$(CONFIG_W1) += w1/
drivers/i3c/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0 + +menuconfig I3C + tristate "I3C support" + select I2C + help + I3C is a serial protocol standardized by the MIPI alliance. + + It's supposed to be backward compatible with I2C while providing + support for high speed transfers and native interrupt support + without the need for extra pins. + + The I3C protocol also standardizes the slave device types and is + mainly designed to communicate with sensors. + + If you want I3C support, you should say Y here and also to the + specific driver for your bus adapter(s) below. + + This I3C support can also be built as a module. If so, the module + will be called i3c. + +if I3C +source "drivers/i3c/master/Kconfig" +endif # I3C
drivers/i3c/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +i3c-y := device.o master.o +obj-$(CONFIG_I3C) += i3c.o +obj-$(CONFIG_I3C) += master/
drivers/i3c/device.c new file +233 -0
233 lines not on this page · raw message
drivers/i3c/internals.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 Cadence Design Systems Inc. +* +* Author: Boris Brezillon <[email protected]> +*/ + +#ifndef I3C_INTERNALS_H +#define I3C_INTERNALS_H + +#include <linux/i3c/master.h> + +extern struct bus_type i3c_bus_type; + +void i3c_bus_normaluse_lock (struct i3c_bus *bus); +void i3c_bus_normaluse_unlock (struct i3c_bus *bus); + +int i3c_dev_do_priv_xfers_locked (struct i3c_dev_desc *dev, +struct i3c_priv_xfer *xfers, +int nxfers); +int i3c_dev_disable_ibi_locked (struct i3c_dev_desc *dev); +int i3c_dev_enable_ibi_locked (struct i3c_dev_desc *dev); +int i3c_dev_request_ibi_locked (struct i3c_dev_desc *dev, +const struct i3c_ibi_setup *req); +void i3c_dev_free_ibi_locked (struct i3c_dev_desc *dev); +#endif /* I3C_INTERNAL_H */
drivers/i3c/master.c new file +2648 -0
2,648 lines not on this page · raw message
drivers/i3c/master/Kconfig new file +0 -0
drivers/i3c/master/Makefile new file +0 -0
include/linux/i3c/ccc.h new file +385 -0
49 lines not on this page · raw message
include/linux/i3c/device.h new file +331 -0
331 lines not on this page · raw message
include/linux/i3c/master.h new file +643 -0
643 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH v9 2/9 docs: driver-api: Add I3C documentation
In reply to Boris BrezillonAdd the I3C documentation describing the protocol, the master driver API and the device driver API.
---
Changes in v9:
- Add Arnd's R-b
Changes in v8:
- None
Changes in v7:
- None
Changes in v6:
- Fix typos reported by Randy
- Add Randy's R-b
Changes in v5:
- Remove useless conf.py file
- Add SPDX headers
Changes in v2:
- Moved out of patch "i3c: Add core I3C infrastructure"
- Add link to the I3C spec
- Move rst files in Documentation/driver-api/i3c/
--- .../driver-api/i3c/device-driver-api.rst | 9 + Documentation/driver-api/i3c/index.rst | 11 + .../driver-api/i3c/master-driver-api.rst | 10 + Documentation/driver-api/i3c/protocol.rst | 203 ++++++++++++++++++ Documentation/driver-api/index.rst | 1 + 5 files changed, 234 insertions(+) create mode 100644 Documentation/driver-api/i3c/device-driver-api.rst create mode 100644 Documentation/driver-api/i3c/index.rst create mode 100644 Documentation/driver-api/i3c/master-driver-api.rst create mode 100644 Documentation/driver-api/i3c/protocol.rst
Documentation/driver-api/i3c/device-driver-api.rst new file +9 -0
@@ -0,0 +1,9 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================== +I3C device driver API +===================== + +.. kernel-doc:: include/linux/i3c/device.h + +.. kernel-doc:: drivers/i3c/device.c
Documentation/driver-api/i3c/index.rst new file +11 -0
@@ -0,0 +1,11 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============= +I3C subsystem +============= + +.. toctree:: + + protocol + device-driver-api + master-driver-api
Documentation/driver-api/i3c/master-driver-api.rst new file +10 -0
@@ -0,0 +1,10 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================ +I3C master controller driver API +================================ + +.. kernel-doc:: drivers/i3c/master.c + +.. kernel-doc:: include/linux/i3c/master.h +
Documentation/driver-api/i3c/protocol.rst new file +203 -0
203 lines not on this page · raw message
Documentation/driver-api/index.rst +1 -0
@@ -32,6 +32,7 @@ available subsections can be seen below. pci spi i2c + i3c/index hsi edac scsi
Signature · 1 line
2.17.1
PATCH v9 3/9 i3c: Add sysfs ABI spec
In reply to Boris BrezillonDocument sysfs files/directories/symlinks exposed by the I3C subsystem.
---
Changes in v9:
- Add Arnd's R-b
Changes in v8:
- None
Changes in v7:
- Bump KernelVersion to 4.20
- Add new entries under i3c-<bus-id> now that the master controller is no longer represented as a device under this directory but implicitly represented by the bus object
Changes in v6:
- none
Changes in v5:
- Fix the kernel version
- Rename address into dynamic_address to match changes done in the code
Changes in v4:
- none
Changes in v3:
- none
Changes in v2:
- new patch
--- Documentation/ABI/testing/sysfs-bus-i3c | 146 ++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-i3c
Documentation/ABI/testing/sysfs-bus-i3c new file +146 -0
@@ -0,0 +1,146 @@ +What: /sys/bus/i3c/devices/i3c-<bus-id> +KernelVersion: 4.20 +Contact: [email protected] +Description: + An I3C bus. This directory will contain one sub-directory per + I3C device present on the bus. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/current_master +KernelVersion: 4.20 +Contact: [email protected] +Description: + Expose the master that owns the bus (<bus-id>-<master-pid>) at + the time this file is read. Note that bus ownership can change + overtime, so there's no guarantee that when the read() call + returns, the value returned is still valid. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/mode +KernelVersion: 4.20 +Contact: [email protected] +Description: + I3C bus mode. Can be "pure", "mixed-fast" or "mixed-slow". See + the I3C specification for a detailed description of what each + of these modes implies. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/i3c_scl_frequency +KernelVersion: 4.20 +Contact: [email protected] +Description: + The frequency (expressed in Hz) of the SCL signal when + operating in I3C SDR mode. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/i2c_scl_frequency +KernelVersion: 4.20 +Contact: [email protected] +Description: + The frequency (expressed in Hz) of the SCL signal when + operating in I2C mode. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/dynamic_address +KernelVersion: 4.20 +Contact: [email protected] +Description: + Dynamic address assigned to the master controller. This + address may change if the bus is re-initialized. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/bcr +KernelVersion: 4.20 +Contact: [email protected] +Description: + BCR stands for Bus Characteristics Register and express the + device capabilities in term of speed, maximum read/write + length, etc. See the I3C specification for more details. + This entry describes the BCR of the master controller driving + the bus. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/dcr +KernelVersion: 4.20 +Contact: [email protected] +Description: + DCR stands for Device Characteristics Register and express the + device capabilities in term of exposed features. See the I3C + specification for more details. + This entry describes the DCR of the master controller driving + the bus. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/pid +KernelVersion: 4.20 +Contact: [email protected] +Description: + PID stands for Provisional ID and is used to uniquely identify + a device on a bus. This PID contains information about the + vendor, the part and an instance ID so that several devices of + the same type can be connected on the same bus. + See the I3C specification for more details. + This entry describes the PID of the master controller driving + the bus. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/hdrcap +KernelVersion: 4.20 +Contact: [email protected] +Description: + Expose the HDR (High Data Rate) capabilities of a device. + Returns a list of supported HDR mode, each element is separated + by space. Modes can be "hdr-ddr", "hdr-tsp" and "hdr-tsl". + See the I3C specification for more details about these HDR + modes. + This entry describes the HDRCAP of the master controller + driving the bus. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid> +KernelVersion: 4.20 +Contact: [email protected] +Description: + An I3C device present on I3C bus identified by <bus-id>. Note + that all devices are represented including the master driving + the bus. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dynamic_address +KernelVersion: 4.20 +Contact: [email protected] +Description: + Dynamic address assigned to device <bus-id>-<device-pid>. This + address may change if the bus is re-initialized. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/bcr +KernelVersion: 4.20 +Contact: [email protected] +Description: + BCR stands for Bus Characteristics Register and express the + device capabilities in term of speed, maximum read/write + length, etc. See the I3C specification for more details. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dcr +KernelVersion: 4.20 +Contact: [email protected] +Description: + DCR stands for Device Characteristics Register and express the + device capabilities in term of exposed features. See the I3C + specification for more details. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/pid +KernelVersion: 4.20 +Contact: [email protected] +Description: + PID stands for Provisional ID and is used to uniquely identify + a device on a bus. This PID contains information about the + vendor, the part and an instance ID so that several devices of + the same type can be connected on the same bus. + See the I3C specification for more details. + +What: /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/hdrcap +KernelVersion: 4.20 +Contact: [email protected] +Description: + Expose the HDR (High Data Rate) capabilities of a device. + Returns a list of supported HDR mode, each element is separated + by space. Modes can be "hdr-ddr", "hdr-tsp" and "hdr-tsl". + See the I3C specification for more details about these HDR + modes. + +What: /sys/bus/i3c/devices/<bus-id>-<device-pid> +KernelVersion: 4.20 +Contact: [email protected] +Description: + These directories are just symbolic links to + /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>.
Signature · 1 line
2.17.1
PATCH v9 4/9 dt-bindings: i3c: Document core bindings
In reply to Boris BrezillonA new I3C subsystem has been added and a generic description has been created to represent the I3C bus and the devices connected on it.
Document this generic representation.
---
Rob,
Can you have a look at this v9. I know you previously acked this binding but I changed a bit the way we declare I2C devices and thus had to drop your Ack.
The IS_I2C_DEV bit no long exists, and we instead consider that any device with the 2nd reg entry set to 0 is an I2C device, which is just fine because this entry is supposed to contain the upper part of the Provisional ID which is basically the MIPI manufacturer ID, and 0 is not a valid manufacturer ID.
By doing that we make reg definition more straightforward and can drop the ugly {I2C,I3C}_DEV() macros.
Regards,
Boris
Changes in v9:
- Rework the way we encode the I2C vs I3C device in the reg property so that we don't need the funky macros to define and I3C or I2C dev
- Drop Rob's Reviewed-by
Changes in v8:
- None
Changes in v7:
- None
Changes in v6:
- None
Changes in v5:
- Add Rob's R-b
Changes in v4:
- Clarify the fact that static address == I3C address and dynamic address == I3C address
- Use i2c-scl-hz in the example
Changes in v3:
- Rename {i2c,i3c}-scl-frequency DT prop into {i2c,i3c}-scl-hz
- Rework the way we expose the provisional ID and LVR information
- Rename dynamic-address into assigned-address
- Enforce the I3C master node name
Changes in v2:
- Define how to describe I3C devices in the DT and when it should be used. Note that the parsing of I3C devices is not yet implemented in the framework. Will be added when someone really needs it.
--- Documentation/devicetree/bindings/i3c/i3c.txt | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 Documentation/devicetree/bindings/i3c/i3c.txt
Documentation/devicetree/bindings/i3c/i3c.txt new file +138 -0
@@ -0,0 +1,138 @@ +Generic device tree bindings for I3C busses +=========================================== + +This document describes generic bindings that should be used to describe I3C +busses in a device tree. + +Required properties +------------------- + +- #address-cells - should be <3>. Read more about addresses below. +- #size-cells - should be <0>. +- compatible - name of the I3C master controller driving the I3C bus + +For other required properties e.g. to describe register sets, +clocks, etc. check the binding documentation of the specific driver. +The node describing an I3C bus should be named i3c-master. + +Optional properties +------------------- + +These properties may not be supported by all I3C master drivers. Each I3C +master bindings should specify which of them are supported. + +- i3c-scl-hz: frequency of the SCL signal used for I3C transfers. + When undefined the core sets it to 12.5MHz. + +- i2c-scl-hz: frequency of the SCL signal used for I2C transfers. + When undefined, the core looks at LVR (Legacy Virtual Register) + values of I2C devices described in the device tree to determine + the maximum I2C frequency. + +I2C devices +=========== + +Each I2C device connected to the bus should be described in a subnode. All +properties described in Documentation/devicetree/bindings/i2c/i2c.txt are +valid here, but several new properties have been added. + +New constraint on existing properties: +-------------------------------------- +- reg: contains 3 cells + + first cell : still encoding the I2C address + + + second cell: shall be 0 + + + third cell: shall encode the I3C LVR (Legacy Virtual Register) + bit[31:8]: unused/ignored + bit[7:5]: I2C device index. Possible values + * 0: I2C device has a 50 ns spike filter + * 1: I2C device does not have a 50 ns spike filter but supports high + frequency on SCL + * 2: I2C device does not have a 50 ns spike filter and is not tolerant + to high frequencies + * 3-7: reserved + + bit[4]: tell whether the device operates in FM (Fast Mode) or FM+ mode + * 0: FM+ mode + * 1: FM mode + + bit[3:0]: device type + * 0-15: reserved + +I3C devices +=========== + +All I3C devices are supposed to support DAA (Dynamic Address Assignment), and +are thus discoverable. So, by default, I3C devices do not have to be described +in the device tree. +This being said, one might want to attach extra resources to these devices, +and those resources may have to be described in the device tree, which in turn +means we have to describe I3C devices. + +Another use case for describing an I3C device in the device tree is when this +I3C device has a static I2C address and we want to assign it a specific I3C +dynamic address before the DAA takes place (so that other devices on the bus +can't take this dynamic address). + +The I3C device should be names <device-type>@<static-i2c-address>,<i3c-pid>, +where device-type is describing the type of device connected on the bus +(gpio-controller, sensor, ...). + +Required properties +------------------- +- reg: contains 3 cells + + first cell : encodes the static I2C address. Should be 0 if the device does + not have one (0 is not a valid I2C address). + + + second and third cells: should encode the ProvisionalID. The second cell + contains the manufacturer ID left-shifted by 1. + The third cell contains ORing of the part ID + left-shifted by 16, the instance ID left-shifted + by 12 and the extra information. This encoding is + following the PID definition provided by the I3C + specification. + +Optional properties +------------------- +- assigned-address: dynamic address to be assigned to this device. This + property is only valid if the I3C device has a static + address (first cell of the reg property != 0). + + +Example: + + i3c-master@d040000 { + compatible = "cdns,i3c-master"; + clocks = <&coreclock>, <&i3csysclock>; + clock-names = "pclk", "sysclk"; + interrupts = <3 0>; + reg = <0x0d040000 0x1000>; + #address-cells = <3>; + #size-cells = <0>; + + status = "okay"; + i2c-scl-hz = <100000>; + + /* I2C device. */ + nunchuk: nunchuk@52 { + compatible = "nintendo,nunchuk"; + reg = <0x52 0x80000010 0x0>; + }; + + /* I3C device with a static I2C address. */ + thermal_sensor: sensor@68,39200144004 { + reg = <0x68 0x392 0x144004>; + assigned-address = <0xa>; + }; + + /* + * I3C device without a static I2C address but requiring + * resources described in the DT. + */ + sensor@0,39200154004 { + reg = <0x0 0x392 0x154004>; + clocks = <&clock_provider 0>; + }; + }; +
Signature · 1 line
2.17.1
Rob Herring
maintainerRe: [PATCH v9 4/9] dt-bindings: i3c: Document core bindings
Quoted 173 lines · Boris Brezillon
A new I3C subsystem has been added and a generic description has been created to represent the I3C bus and the devices connected on it.
Document this generic representation.
Cc Rob Herring <[email protected]>Signed-off-by Boris Brezillon <[email protected]>---
Rob,Can you have a look at this v9. I know you previously acked this binding but I changed a bit the way we declare I2C devices and thus had to drop your Ack.
TheIS_I2C_DEVbit no long exists, and we instead consider that any device with the 2nd reg entry set to 0 is an I2C device, which is just fine because this entry is supposed to contain the upper part of the Provisional ID which is basically the MIPI manufacturer ID, and 0 is not a valid manufacturer ID.By doing that we make reg definition more straightforward and can drop the ugly {I2C,I3C}_DEV() macros.
Regards,
Boris
Changes in v9:
- Rework the way we encode the I2C vs I3C device in the reg property so that we don't need the funky macros to define and I3C or I2C dev
- Drop Rob's Reviewed-byChanges in v8:
- NoneChanges in v7:
- NoneChanges in v6:
- NoneChanges in v5:
- Add Rob's R-bChanges in v4:
- Clarify the fact that static address == I3C address and dynamic address == I3C address
- Use i2c-scl-hz in the exampleChanges in v3:
- Rename {i2c,i3c}-scl-frequency DT prop into {i2c,i3c}-scl-hz
- Rework the way we expose the provisional ID and LVR information
- Rename dynamic-address into assigned-address
- Enforce the I3C master node nameChanges in v2:
- Define how to describe I3C devices in the DT and when it should be used. Note that the parsing of I3C devices is not yet implemented in the framework. Will be added when someone really needs it.--- Documentation/devicetree/bindings/i3c/i3c.txt | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 Documentation/devicetree/bindings/i3c/i3c.txtDocumentation/devicetree/bindings/i3c/i3c.txt new file +104
-0@@ -0,0 +1,138 @@ +Generic device tree bindings for I3C busses +=========================================== + +This document describes generic bindings that should be used to describe I3C +busses in a device tree. + +Required properties +------------------- + +- #address-cells - should be <3>. Read more about addresses below. +- #size-cells - should be <0>. +- compatible - name of the I3C master controller driving the I3C bus + +For other required properties e.g. to describe register sets, +clocks, etc. check the binding documentation of the specific driver. +The node describing an I3C bus should be named i3c-master. + +Optional properties +------------------- + +These properties may not be supported by all I3C master drivers. Each I3C +master bindings should specify which of them are supported. + +- i3c-scl-hz: frequency of the SCL signal used for I3C transfers. + When undefined the core sets it to 12.5MHz. + +- i2c-scl-hz: frequency of the SCL signal used for I2C transfers. + When undefined, the core looks at LVR (Legacy Virtual Register) + values of I2C devices described in the device tree to determine + the maximum I2C frequency. + +I2C devices +=========== + +Each I2C device connected to the bus should be described in a subnode. All +properties described in Documentation/devicetree/bindings/i2c/i2c.txt are +valid here, but several new properties have been added. + +New constraint on existing properties: +-------------------------------------- +- reg: contains 3 cells + + first cell : still encoding the I2C address + + + second cell: shall be 0 + + + third cell: shall encode the I3C LVR (Legacy Virtual Register) + bit[31:8]: unused/ignored + bit[7:5]: I2C device index. Possible values + * 0: I2C device has a 50 ns spike filter + * 1: I2C device does not have a 50 ns spike filter but supports high + frequency on SCL + * 2: I2C device does not have a 50 ns spike filter and is not tolerant + to high frequencies + * 3-7: reserved + + bit[4]: tell whether the device operates in FM (Fast Mode) or FM+ mode + * 0: FM+ mode + * 1: FM mode + + bit[3:0]: device type + * 0-15: reserved + +I3C devices +=========== + +All I3C devices are supposed to support DAA (Dynamic Address Assignment), and +are thus discoverable. So, by default, I3C devices do not have to be described +in the device tree. +This being said, one might want to attach extra resources to these devices, +and those resources may have to be described in the device tree, which in turn +means we have to describe I3C devices. + +Another use case for describing an I3C device in the device tree is when this +I3C device has a static I2C address and we want to assign it a specific I3C +dynamic address before the DAA takes place (so that other devices on the bus +can't take this dynamic address). + +The I3C device should be names <device-type>@<static-i2c-address>,<i3c-pid>, +where device-type is describing the type of device connected on the bus +(gpio-controller, sensor, ...). + +Required properties +------------------- +- reg: contains 3 cells + + first cell : encodes the static I2C address. Should be 0 if the device does + not have one (0 is not a valid I2C address). + + + second and third cells: should encode the ProvisionalID. The second cell + contains the manufacturer ID left-shifted by 1. + The third cell contains ORing of the part ID + left-shifted by 16, the instance ID left-shifted + by 12 and the extra information. This encoding is + following the PID definition provided by the I3C + specification. + +Optional properties +------------------- +- assigned-address: dynamic address to be assigned to this device. This + property is only valid if the I3C device has a static + address (first cell of the reg property != 0). + + +Example: +
Documentation/devicetree/bindings/i3c/i3c.txt line 114
Quoted 10 lines
Documentation/devicetree/bindings/i3c/i3c.txt new file +10
-0+ i3c-master@d040000 { + compatible = "cdns,i3c-master"; + clocks = <&coreclock>, <&i3csysclock>; + clock-names = "pclk", "sysclk"; + interrupts = <3 0>; + reg = <0x0d040000 0x1000>; + #address-cells = <3>; + #size-cells = <0>; + + status = "okay";
Don't show status in examples.
Documentation/devicetree/bindings/i3c/i3c.txt line 118
Quoted 4 lines
Documentation/devicetree/bindings/i3c/i3c.txt new file +4
-0+ i2c-scl-hz = <100000>; + + /* I2C device. */ + nunchuk: nunchuk@52 {
Might clarify somewhere above that I2C only device unit-address is just the 1st cell value.
Documentation/devicetree/bindings/i3c/i3c.txt line 120
Quoted 2 lines
Documentation/devicetree/bindings/i3c/i3c.txt new file +2
-0+ compatible = "nintendo,nunchuk"; + reg = <0x52 0x80000010 0x0>;
Cell 2 should be updated?
Quoted 21 lines
Documentation/devicetree/bindings/i3c/i3c.txt new file +18
-0+ }; + + /* I3C device with a static I2C address. */ + thermal_sensor: sensor@68,39200144004 { + reg = <0x68 0x392 0x144004>; + assigned-address = <0xa>; + }; + + /* + * I3C device without a static I2C address but requiring + * resources described in the DT. + */ + sensor@0,39200154004 { + reg = <0x0 0x392 0x154004>; + clocks = <&clock_provider 0>; + }; + }; +Signature · 1 line
2.17.1
PATCH v9 5/9 MAINTAINERS: Add myself as the I3C subsystem maintainer
In reply to Boris BrezillonCreate an entry for the I3C subsystem and mark it as maintained by me. There's no official git repository, patchwork instance, mailing list or website yet, but this will be added after the subsystem has been accepted.
---
Changes in v9:
- None
Changes in v8:
- None
Changes in v7:
- Add a ML (not created yet) and a git repo
Changes in v5:
- Add the sysfs ABI file
--- MAINTAINERS | 12 ++++++++++++ 1 file changed, 12 insertions(+)
MAINTAINERS +12 -0
@@ -6918,6 +6918,18 @@ L: [email protected] S: Maintained F: drivers/i2c/i2c-stub.c +I3C SUBSYSTEM +M: Boris Brezillon <[email protected]> +L: [email protected] +T: git git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux.git +S: Maintained +F: Documentation/ABI/testing/sysfs-bus-i3c +F: Documentation/devicetree/bindings/i3c/ +F: Documentation/driver-api/i3c +F: drivers/i3c/ +F: include/linux/i3c/ +F: include/dt-bindings/i3c/ + IA64 (Itanium) PLATFORM M: Tony Luck <[email protected]> M: Fenghua Yu <[email protected]>
Signature · 1 line
2.17.1
PATCH v9 6/9 i3c: master: Add driver for Cadence IP
In reply to Boris BrezillonAdd a driver for Cadence I3C master IP.
---
Changes in v9:
- Change the 'depends on' rule (suggested by Arnd)
- Use {read,write}sl() instead of __raw_{readl,writem}() (suggested by Arnd)
- Add Arnd's R-b
Changes in v8:
- Adjust code to match changes done in the core (bus embedded in master)
Changes in v7:
- Fix readsl/writesl() usage
- Add a depends on ARM || ARM64 || XTENSA to forbid selection of this driver on platforms that are not implementing readsl/writesl
Changes in v6:
- Rework the attach/detach logic to match the new way of doing things.
- Use kcalloc() where appropriate
- Simplfy access to the RX/TX/IBI_DATA FIFOs
Changes in v5:
- Drop unused len var in cdns_i3c_master_handle_ibi()
- Get IBIR and CMDR depth from CONF_STATUS0
- s/2017/2018/ in copyright header
- Fix coding style issues
Changes in v4:
- Fix potential unsigned integer underflow
- Add missing static specific on IBI related functions
Changes in v3:
- Adjust to match I3C framework changes
- Implement support the CMD RESPONSE QUEUE and IBI QUEUE added in the latest revision of Cadence master IP
- Remove support for HDR modes
Changes in v2:
- Add basic IBI support. Note that the IP is not really reliable with regards to IBI because you can't extract IBI payloads as soon as you have more than one IBI waiting in the HW queue. This is something that will hopefully be addressed in future revisions of this IP
- Add a simple xfer queueing mechanism to optimize message queuing.
- Fix a few bugs
- Add support for Hot Join
--- drivers/i3c/master/Kconfig | 6 + drivers/i3c/master/Makefile | 1 + drivers/i3c/master/i3c-master-cdns.c | 1671 ++++++++++++++++++++++++++ 3 files changed, 1678 insertions(+) create mode 100644 drivers/i3c/master/i3c-master-cdns.c
drivers/i3c/master/Kconfig +6 -0
@@ -0,0 +1,6 @@ +config CDNS_I3C_MASTER + tristate "Cadence I3C master driver" + depends on I3C + depends on !(ALPHA || PARISC) + help + Enable this driver if you want to support Cadence I3C master block.
drivers/i3c/master/Makefile +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_CDNS_I3C_MASTER) += i3c-master-cdns.o
drivers/i3c/master/i3c-master-cdns.c new file +1671 -0
1,671 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 5 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
drivers/i3c/master/i3c-master-cdns.c new file +5
-0+ +static void cdns_i3c_master_rd_from_rx_fifo (struct cdns_i3c_master *master, +u8 *bytes,int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );
Vitor reported a problem with readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:
for (i = 0; i < nbytes; i += 4) {
u32 tmp = __raw_readl(...);
memcpy(bytes + i, &tmp,
nbytes - i > 4 ? 4 : nbytes - i);
}drivers/i3c/master/i3c-master-cdns.c line 441
Quoted 7 lines
drivers/i3c/master/i3c-master-cdns.c new file +7
-0+if (nbytes &3 ) { +u32 tmp; + +readsl (master->regs +RX_FIFO , &tmp,1 ); +memcpy (bytes + (nbytes & ~3 ), &tmp, nbytes &3 ); + } +}
Regards,
Boris
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 16 lines · Boris Brezillon
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 5 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
drivers/i3c/master/i3c-master-cdns.c new file +5
-0+ +static void cdns_i3c_master_rd_from_rx_fifo (struct cdns_i3c_master *master, +u8 *bytes,int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );Vitor reported a problem with
readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:
Quoted 2 lines
for (i = 0; i < nbytes; i += 4) {
u32 tmp = __raw_readl(...);Pls, do not use __raw io.
Quoted 16 lines
memcpy(bytes + i, &tmp, nbytes - i > 4 ? 4 : nbytes - i); }drivers/i3c/master/i3c-master-cdns.c line 441
Quoted 7 lines
drivers/i3c/master/i3c-master-cdns.c new file +7
-0+if (nbytes &3 ) { +u32 tmp; + +readsl (master->regs +RX_FIFO , &tmp,1 ); +memcpy (bytes + (nbytes & ~3 ), &tmp, nbytes &3 ); + } +}Regards,
Boris
Signature · 2 lines
regards, -grygorii
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 17 lines · On Wed, 24 Oct 2018 15:25:17 -0500 Grygorii Strashko…
Quoted 16 lines · Boris Brezillon
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 5 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
drivers/i3c/master/i3c-master-cdns.c new file +5
-0+ +static void cdns_i3c_master_rd_from_rx_fifo (struct cdns_i3c_master *master, +u8 *bytes,int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );Vitor reported a problem with
readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:
Quoted 4 lines
Quoted 2 lines
for (i = 0; i < nbytes; i += 4) { u32 tmp = __raw_readl(...);Pls, do not use
__rawio.
Except this is exactly what I want here, unless you have a replacement for "readl() without a mem-barrier and without endianness conversion"
Quoted 18 lines
Quoted 17 lines
memcpy(bytes + i, &tmp, nbytes - i > 4 ? 4 : nbytes - i); }drivers/i3c/master/i3c-master-cdns.c line 441
Quoted 7 lines
drivers/i3c/master/i3c-master-cdns.c new file +7
-0+if (nbytes &3 ) { +u32 tmp; + +readsl (master->regs +RX_FIFO , &tmp,1 ); +memcpy (bytes + (nbytes & ~3 ), &tmp, nbytes &3 ); + } +}Regards,
Boris
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 20 lines · Boris Brezillon
Quoted 17 lines · On Wed, 24 Oct 2018 15:25:17 -0500 Grygorii Strashko…
Quoted 16 lines · Boris Brezillon
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 5 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
drivers/i3c/master/i3c-master-cdns.c new file +5
-0+ +static void cdns_i3c_master_rd_from_rx_fifo (struct cdns_i3c_master *master, +u8 *bytes,int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );Vitor reported a problem with
readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
for (i = 0; i < nbytes; i += 4) { u32 tmp = __raw_readl(...);Pls, do not use
__rawio.Except this is exactly what I want here, unless you have a replacement for "
readl()without a mem-barrier and without endianness conversion"
Not sure why endianness is the problem. readl_relaxed? Sry, I've missed that this is part of the driver not i3c core, so minor/ignore.
Signature · 2 lines
regards, -grygorii
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 24 lines · On Wed, 24 Oct 2018 17:43:00 -0500 Grygorii Strashko…
Quoted 23 lines · Boris Brezillon
Quoted 20 lines · On Wed, 24 Oct 2018 15:25:17 -0500 Grygorii Strashko…
Quoted 18 lines · Boris Brezillon
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 5 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
drivers/i3c/master/i3c-master-cdns.c new file +5
-0+ +static void cdns_i3c_master_rd_from_rx_fifo (struct cdns_i3c_master *master, +u8 *bytes,int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );Vitor reported a problem with
readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:for (i = 0; i < nbytes; i += 4) { u32 tmp = __raw_readl(...);
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Pls, do not use
__rawio.Except this is exactly what I want here, unless you have a replacement for "
readl()without a mem-barrier and without endianness conversion"Not sure why endianness is the problem.
readl_relaxed?
Because we want to read a stream of bytes, and, if we have a CPU that is operating in big-endian (ARM kernels can configured in BE or LE), byte ordering will be messed up (the controller is LE).
If I use readl_relaxed(), I'll then have to call cpu_to_le32(), and finally copy the result to the buffer.
Quoted 3 lines
Sry, I've missed that this is part of the driver not i3c core, so minor/ignore.
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
In reply to Boris BrezillonQuoted 17 lines · Boris Brezillon
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 6 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
(quoted diff) +2
-0+ +static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master*master,
drivers/i3c/master/i3c-master-cdns.c new file +3
-0+ u8 *bytes, int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );Vitor reported a problem with
readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:
Quoted 5 lines
for (i = 0; i < nbytes; i += 4) {
u32 tmp = __raw_readl(...);
memcpy(bytes + i, &tmp,
nbytes - i > 4 ? 4 : nbytes - i);
}Could we maybe mandate that the buffer itself must be aligned here? What would be a reason why we see an unaligned target buffer?
The open-coded loop should generally work (maybe a little slower), but it does seem error-prone to use __raw_readl() in general.
Arnd
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 18 lines · On Thu, 25 Oct 2018 17:30:26 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 17 lines · Boris Brezillon
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 6 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
(quoted diff) +2
-0+ +static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master*master,
drivers/i3c/master/i3c-master-cdns.c new file +3
-0+ u8 *bytes, int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );Vitor reported a problem with
readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:
Quoted 8 lines
Quoted 5 lines
for (i = 0; i < nbytes; i += 4) { u32 tmp = __raw_readl(...); memcpy(bytes + i, &tmp, nbytes - i > 4 ? 4 : nbytes - i); }Could we maybe mandate that the buffer itself must be aligned here? What would be a reason why we see an unaligned target buffer?
Well, the buffers we pass to i3c_send_ccc_cmd() are not necessarily aligned because they're not dynamically allocated (allocated on the stack) and are not naturally aligned on 32-bits (either because they are smaller than 32bits or because the struct is declared __packed).
I guess I could dynamically allocate the payload, but that requires going over all users of i3c_send_ccc_cmd() to patch them.
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 31 lines · Boris Brezillon
Quoted 18 lines · On Thu, 25 Oct 2018 17:30:26 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 17 lines · Boris Brezillon
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 6 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
(quoted diff) +2
-0+ +static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master*master,
drivers/i3c/master/i3c-master-cdns.c new file +3
-0+ u8 *bytes, int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );Vitor reported a problem with
readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:Quoted 8 lines
Quoted 5 lines
for (i = 0; i < nbytes; i += 4) { u32 tmp = __raw_readl(...); memcpy(bytes + i, &tmp, nbytes - i > 4 ? 4 : nbytes - i); }Could we maybe mandate that the buffer itself must be aligned here? What would be a reason why we see an unaligned target buffer?
Quoted 7 lines
Well, the buffers we pass to
i3c_send_ccc_cmd()are not necessarily aligned because they're not dynamically allocated (allocated on the stack) and are not naturally aligned on 32-bits (either because they are smaller than 32bits or because the struct is declared__packed).I guess I could dynamically allocate the payload, but that requires going over all users of
i3c_send_ccc_cmd()to patch them.
This reminds me that Wolfram mentioned in his ELC talk that the buffers on i3c should all be DMA capable to make life easier for i3c master drivers that want to implement DMA transfers.
If we have buffers here that are not aligned to cache lines (or even just 32 bit words), doesn't that also mean that the same buffers are not DMA capable either?
Arnd
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 38 lines · On Thu, 25 Oct 2018 18:13:51 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 36 lines · Boris Brezillon
Quoted 18 lines · On Thu, 25 Oct 2018 17:30:26 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 17 lines · Boris Brezillon
Hi Arnd,
drivers/i3c/master/i3c-master-cdns.c line 434
Quoted 6 lines · On Mon, 22 Oct 2018 15:34:01 +0200 Boris Brezillon…
(quoted diff) +2
-0+ +static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master*master,
drivers/i3c/master/i3c-master-cdns.c new file +3
-0+ u8 *bytes, int nbytes) +{ +readsl (master->regs +RX_FIFO , bytes, nbytes /4 );Vitor reported a problem with
readsl(): this function expects the 2nd argument to be aligned on 32-bit, which is not guaranteed here. Unless you see a better solution, I'll switch back to a loop doing:Quoted 8 lines
Quoted 5 lines
for (i = 0; i < nbytes; i += 4) { u32 tmp = __raw_readl(...); memcpy(bytes + i, &tmp, nbytes - i > 4 ? 4 : nbytes - i); }Could we maybe mandate that the buffer itself must be aligned here? What would be a reason why we see an unaligned target buffer?
Well, the buffers we pass to
i3c_send_ccc_cmd()are not necessarily aligned because they're not dynamically allocated (allocated on the stack) and are not naturally aligned on 32-bits (either because they are smaller than 32bits or because the struct is declared__packed).
Quoted 6 lines
Quoted 2 lines
I guess I could dynamically allocate the payload, but that requires going over all users of
i3c_send_ccc_cmd()to patch them.This reminds me that Wolfram mentioned in his ELC talk that the buffers on i3c should all be DMA capable to make life easier for i3c master drivers that want to implement DMA transfers.
And this is the case for all buffers passed to i3c_device_do_priv_xfers() (and soon i3c_device_send_hdr_cmd()), but I did not enforce that for the internal i3c_master_send_ccc_cmd_locked() helper, maybe I should... It was just convenient to place the object to be transmitted/received on the stack.
Quoted 4 lines
If we have buffers here that are not aligned to cache lines (or even just 32 bit words), doesn't that also mean that the same buffers are not DMA capable either?
Yep, if it's not cache-line-aligned (and on the stack), it's not DMA-able.
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 13 lines · Boris Brezillon
On Thu, 25 Oct 2018 18:13:51 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 10 lines · Boris Brezillon
Quoted 6 lines
Quoted 2 lines · On Thu, 25 Oct 2018 17:30:26 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 1 line · Boris Brezillon
On Mon, 22 Oct 2018 15:34:01 +0200
I guess I could dynamically allocate the payload, but that requires going over all users of
i3c_send_ccc_cmd()to patch them.This reminds me that Wolfram mentioned in his ELC talk that the buffers on i3c should all be DMA capable to make life easier for i3c master drivers that want to implement DMA transfers.
Quoted 6 lines
And this is the case for all buffers passed to
i3c_device_do_priv_xfers()(and sooni3c_device_send_hdr_cmd()), but I did not enforce that for the internali3c_master_send_ccc_cmd_locked()helper, maybe I should... It was just convenient to place the object to be transmitted/received on the stack.
Ok. Is i3c_master_send_ccc_cmd_locked() what implements the public interfaces then, or is this something else?
If you place a buffer on the stack, it is not DMA capable, but it is guaranteed to be at least 32-bit word aligned, and should not cause an exception in readsl(), unless it starts with a couple of (not multiple of four) extra bytes that are not sent to the devices. Is that what happens here?
Quoted 6 lines
Quoted 3 lines
If we have buffers here that are not aligned to cache lines (or even just 32 bit words), doesn't that also mean that the same buffers are not DMA capable either?
Yep, if it's not cache-line-aligned (and on the stack), it's not DMA-able.
This sounds like a more fundamental problem to solve first then. Obviously it is incredibly /useful/ to be able to put short i2c or i3c messages on the stack, but allowing that in general also prevents the use of DMA without bounce buffers.
One way to address this might be to always bounce any messages that are less than a cache line through a (pre-)kmallocated buffer, and require any longer messages to be cache capable. This could also solve the issue with readsl(), but it would be a rather confusing user interface.
Another option might be to have separate interfaces for "short" and "long" messages at the API level and have distinct rules for those: short would always be bounced by the i3c code, and long puts restrictions on the buffer location.
Arnd
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Hi Arnd,
Quoted 22 lines · On Fri, 26 Oct 2018 09:43:25 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 13 lines · Boris Brezillon
On Thu, 25 Oct 2018 18:13:51 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 10 lines · Boris Brezillon
Quoted 6 lines
Quoted 2 lines · On Thu, 25 Oct 2018 17:30:26 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 1 line · Boris Brezillon
On Mon, 22 Oct 2018 15:34:01 +0200
I guess I could dynamically allocate the payload, but that requires going over all users of
i3c_send_ccc_cmd()to patch them.This reminds me that Wolfram mentioned in his ELC talk that the buffers on i3c should all be DMA capable to make life easier for i3c master drivers that want to implement DMA transfers.
Quoted 6 lines
And this is the case for all buffers passed to
i3c_device_do_priv_xfers()(and sooni3c_device_send_hdr_cmd()), but I did not enforce that for the internali3c_master_send_ccc_cmd_locked()helper, maybe I should... It was just convenient to place the object to be transmitted/received on the stack.
Quoted 2 lines
Ok. Is
i3c_master_send_ccc_cmd_locked()what implements the public interfaces then, or is this something else?
i3c_master_send_ccc_cmd_locked() calls master->ops->send_ccc_cmd(), so it's part of the master controller interface.
Quoted 6 lines
If you place a buffer on the stack, it is not DMA capable, but it is guaranteed to be at least 32-bit word aligned, and should not cause an exception in
readsl(), unless it starts with a couple of (not multiple of four) extra bytes that are not sent to the devices. Is that what happens here?
Here is the report I received from Vitor:
"
Hi Boris,
I'm trying this new patch-set version but I get some issues when use
readsl() function.
Basically the system complain about memory alignment.
As exemple when I try to read the PID from the device
> +static int i3c_master_getpid_locked(struct i3c_master_controller *master,
> + struct i3c_device_info *info)
> +{
> + struct i3c_ccc_getpid getpid;
at this point the getpid struct it is already unaligned with
i3c_master_getpid_locked:1129 getpid_add=0x9a249c7a
> + struct i3c_ccc_cmd_dest dest = {
> + .addr = info->dyn_addr,
> + .payload.len = sizeof(struct i3c_ccc_getpid),
> + .payload.data = &getpid,
> + };
> + struct i3c_ccc_cmd cmd = {
> + .rnw = true,
> + .id = I3C_CCC_GETPID,
> + .dests = &dest,
> + .ndests = 1,
> + };
> + int ret, i;
> +
> + ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
> + if (ret)
> + return ret;
> +
> + info->pid = 0;
> + for (i = 0; i < sizeof(getpid.pid); i++) {
> + int sft = (sizeof(getpid.pid) - i - 1) * 8;
> +
> + info->pid |= (u64)getpid.pid[i] << sft;
> + }
> +
> + return 0;
> +}
> +
and them when
static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
u8 *bytes, int nbytes)
{
readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);
...
}
the system crash.
Misaligned Access
Path: (null)
CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.0-rc1 #88
[ECR ]: 0x00230400 => Misaligned r/w from 0x9a249c7a
[EFA ]: 0x9a249c7a
[BLINK ]: dw_i3c_master_irq_handler+0x200/0x2fc [dw_i3c_master]
[ERET ]: dw_i3c_master_irq_handler+0x224/0x2fc [dw_i3c_master]
[STAT32]: 0x00000a4c : K DE A1 E2
BTA: 0x70038e44 SP: 0x8071fe58 FP: 0x00000000
LPS: 0x8060e63e LPE: 0x8060e642 LPC: 0x00000000
r00: 0x00000033 r01: 0x00000004 r02: 0x00000000
r03: 0xd0002014 r04: 0x00000006 r05: 0x00000000
r06: 0x9a249c7a r07: 0x39307260 r08: 0xe10b6900
r09: 0x00000013 r10: 0x00000000 r11: 0x000000c9
r12: 0x0a613763
Do you have any idea about this?
Best regards,
Vitor Soares"
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
If we have buffers here that are not aligned to cache lines (or even just 32 bit words), doesn't that also mean that the same buffers are not DMA capable either?
Quoted 7 lines
Quoted 2 lines
Yep, if it's not cache-line-aligned (and on the stack), it's not DMA-able.
This sounds like a more fundamental problem to solve first then. Obviously it is incredibly /useful/ to be able to put short i2c or i3c messages on the stack, but allowing that in general also prevents the use of DMA without bounce buffers.
Actually, we have the same problem in MTD (UBI passes vmalloced buffers to the MTD stack), so I understand this concern very well, and I agree that enforcing all buffers passed to the controller to be DMA capable is the right thing to do.
I guess I just didn't think about internal APIs when I made this modification which explains why CCC cmds were left behind.
Quoted 7 lines
One way to address this might be to always bounce any messages that are less than a cache line through a (pre-)kmallocated buffer, and require any longer messages to be cache capable. This could also solve the issue with
readsl(), but it would be a rather confusing user interface.
Quoted 5 lines
Another option might be to have separate interfaces for "short" and "long" messages at the API level and have distinct rules for those: short would always be bounced by the i3c code, and long puts restrictions on the buffer location.
Hm, let's keep the API simple. I'll just mandate that all payload bufs passed to i3c_master_send_ccc_cmd_locked() be dynamically allocated.
Thanks for your feedback.
Boris
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 51 lines · Boris Brezillon
Quoted 7 lines · On Fri, 26 Oct 2018 09:43:25 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 3 lines · Boris Brezillon
On Thu, 25 Oct 2018 18:13:51 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 1 line · Boris Brezillon
Quoted 1 line
On Thu, 25 Oct 2018 17:30:26 +0200
Ok. Is
i3c_master_send_ccc_cmd_locked()what implements the public interfaces then, or is this something else?
i3c_master_send_ccc_cmd_locked()callsmaster->ops->send_ccc_cmd(), so it's part of the master controller interface.Quoted 6 lines
If you place a buffer on the stack, it is not DMA capable, but it is guaranteed to be at least 32-bit word aligned, and should not cause an exception in
readsl(), unless it starts with a couple of (not multiple of four) extra bytes that are not sent to the devices. Is that what happens here?Here is the report I received from Vitor:
"
Hi Boris, I'm trying this new patch-set version but I get some issues when use readsl() function. Basically the system complain about memory alignment. > +static int i3c_master_getpid_locked(struct i3c_master_controller *master, > + struct i3c_device_info *info) > +{ > + struct i3c_ccc_getpid getpid; at this point the getpid struct it is already unaligned with i3c_master_getpid_locked:1129 getpid_add=0x9a249c7a > + struct i3c_ccc_cmd_dest dest = { > + .addr = info->dyn_addr, > + .payload.len = sizeof(struct i3c_ccc_getpid), > + .payload.data = &getpid, > + }; > +} > +
Quoted 8 lines
and them when
static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
u8 *bytes, int nbytes)
{
readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);
...
}Ok, I spent an hour chasing the ARM implementation and finding no way this could go wrong here. I see that 'struct i3c_ccc_getpid' may be misaligned on the stack (it normally won't be), and that the ARM readsl() has a lot of extra code to handle unaligned output. However, the dump that Vitor reports
Quoted 3 lines
[ECR ]: 0x00230400 => Misaligned r/w from 0x9a249c7a
[EFA ]: 0x9a249c7a
[BLINK ]: dw_i3c_master_irq_handler+0x200/0x2fc [dw_i3c_master]Is from an arch/arc kernel that uses asm-generic/io.h, and that stores the output using a u32 pointer:
static inline void readsl(const volatile void __iomem *addr, void *buffer,
unsigned int count)
{
if (count) {
u32 *buf = buffer;
do {
u32 x = __raw_readl(addr);
*buf++ = x;
} while (--count);
}
}This is apparently not allowed on ARC when 'buffer' is unaligned. I think what we need here is to use put_unaligned() instead of the pointer dereference. For architectures that can do unaligned accesses, the result is the same, but for ARC it will fix the problem.
Quoted 6 lines
Quoted 6 lines
One way to address this might be to always bounce any messages that are less than a cache line through a (pre-)kmallocated buffer, and require any longer messages to be cache capable. This could also solve the issue with
readsl(), but it would be a rather confusing user interface.
Quoted 8 lines
Quoted 5 lines
Another option might be to have separate interfaces for "short" and "long" messages at the API level and have distinct rules for those: short would always be bounced by the i3c code, and long puts restrictions on the buffer location.
Hm, let's keep the API simple. I'll just mandate that all payload bufs passed to
i3c_master_send_ccc_cmd_locked()be dynamically allocated.
Ok. What about i2c commands sent to the same i3c controller then? Do we need to copy those to satisfy the requirements of the i3c layer?
Arnd
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 62 lines · On Fri, 26 Oct 2018 12:01:52 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 51 lines · Boris Brezillon
Quoted 7 lines · On Fri, 26 Oct 2018 09:43:25 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 3 lines · Boris Brezillon
On Thu, 25 Oct 2018 18:13:51 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 1 line · Boris Brezillon
Quoted 1 line
On Thu, 25 Oct 2018 17:30:26 +0200
Ok. Is
i3c_master_send_ccc_cmd_locked()what implements the public interfaces then, or is this something else?
i3c_master_send_ccc_cmd_locked()callsmaster->ops->send_ccc_cmd(), so it's part of the master controller interface.Quoted 6 lines
If you place a buffer on the stack, it is not DMA capable, but it is guaranteed to be at least 32-bit word aligned, and should not cause an exception in
readsl(), unless it starts with a couple of (not multiple of four) extra bytes that are not sent to the devices. Is that what happens here?Here is the report I received from Vitor:
"
Hi Boris, I'm trying this new patch-set version but I get some issues when use readsl() function. Basically the system complain about memory alignment. > +static int i3c_master_getpid_locked(struct i3c_master_controller *master, > + struct i3c_device_info *info) > +{ > + struct i3c_ccc_getpid getpid; at this point the getpid struct it is already unaligned with i3c_master_getpid_locked:1129 getpid_add=0x9a249c7a > + struct i3c_ccc_cmd_dest dest = { > + .addr = info->dyn_addr, > + .payload.len = sizeof(struct i3c_ccc_getpid), > + .payload.data = &getpid, > + }; > +} > +Quoted 8 lines
and them when static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master, u8 *bytes, int nbytes) { readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4); ... }
Quoted 5 lines
Ok, I spent an hour chasing the ARM implementation and finding no way this could go wrong here. I see that 'struct
i3c_ccc_getpid' may be misaligned on the stack (it normally won't be), and that the ARMreadsl()has a lot of extra code to handle unaligned output.
I didn't have this problem on xtensa either.
Quoted 22 lines
However, the dump that Vitor reports
Quoted 3 lines
[ECR ]: 0x00230400 => Misaligned r/w from 0x9a249c7a [EFA ]: 0x9a249c7a [BLINK ]: dw_i3c_master_irq_handler+0x200/0x2fc [dw_i3c_master]Is from an
arch/arckernel that usesasm-generic/io.h, and that stores the output using a u32 pointer:static inline void readsl(const volatile void
__iomem*addr, void *buffer,
unsigned int count){ if (count) { u32 *buf = buffer; do { u32 x = __raw_readl(addr); *buf++ = x; } while (--count); } }
Quoted 5 lines
This is apparently not allowed on ARC when 'buffer' is unaligned. I think what we need here is to use
put_unaligned()instead of the pointer dereference. For architectures that can do unaligned accesses, the result is the same, but for ARC it will fix the problem.
Okay, so writesl()/readsl() should deal with unaligned pointers, and default implementations should be fixed. I guess you'll send a patch to use put/get_unaligned().
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
One way to address this might be to always bounce any messages that are less than a cache line through a (pre-)kmallocated buffer, and require any longer messages to be cache capable. This could also solve the issue with
readsl(), but it would be a rather confusing user interface.Another option might be to have separate interfaces for "short" and "long" messages at the API level and have distinct rules for those: short would always be bounced by the i3c code, and long puts restrictions on the buffer location.
Quoted 5 lines
Quoted 2 lines
Hm, let's keep the API simple. I'll just mandate that all payload bufs passed to
i3c_master_send_ccc_cmd_locked()be dynamically allocated.Ok. What about i2c commands sent to the same i3c controller then?
Still not taken care of.
Quoted 2 lines
Do we need to copy those to satisfy the requirements of the i3c layer?
I guess we should. The question is, should we do that unconditionally or should we try to optimize thins with something like:
if (!virt_addr_valid(xfer->buf) || object_is_on_stack(xfer->buf)) /* Alloc bounce buf. */ else /* Use provided buf. */
Re: [PATCH v9 6/9] i3c: master: Add driver for Cadence IP
Quoted 19 lines · Boris Brezillon
Quoted 9 lines · On Fri, 26 Oct 2018 12:01:52 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 7 lines · Boris Brezillon
Quoted 4 lines · On Fri, 26 Oct 2018 09:43:25 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 2 lines · Boris Brezillon
On Thu, 25 Oct 2018 18:13:51 +0200 Arnd Bergmann <[email protected]> wrote:
On Thu, Oct 25, 2018 at 6:07 PM Boris Brezillon <[email protected]> wrote:Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
On Thu, 25 Oct 2018 17:30:26 +0200
This is apparently not allowed on ARC when 'buffer' is unaligned. I think what we need here is to use
put_unaligned()instead of the pointer dereference. For architectures that can do unaligned accesses, the result is the same, but for ARC it will fix the problem.
Quoted 3 lines
Okay, so writesl()/readsl() should deal with unaligned pointers, and default implementations should be fixed. I guess you'll send a patch to use put/get_unaligned().
That's one way of doing it, though thinking about it some more, this can also introduce overhead on machines that don't support unaligned buffers and only work on drivers that are guaranteed to see fully aligned data.
We could also override these specifically for ARC, and risk running into the same problem elsewhere, rather than be sure to fix everyone while risking to introduce noticeable performance regressions in existing drivers.
Quoted 23 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
One way to address this might be to always bounce any messages that are less than a cache line through a (pre-)kmallocated buffer, and require any longer messages to be cache capable. This could also solve the issue with
readsl(), but it would be a rather confusing user interface.Another option might be to have separate interfaces for "short" and "long" messages at the API level and have distinct rules for those: short would always be bounced by the i3c code, and long puts restrictions on the buffer location.
Quoted 5 lines
Quoted 2 lines
Hm, let's keep the API simple. I'll just mandate that all payload bufs passed to
i3c_master_send_ccc_cmd_locked()be dynamically allocated.Ok. What about i2c commands sent to the same i3c controller then?
Still not taken care of.
Quoted 2 lines
Do we need to copy those to satisfy the requirements of the i3c layer?
Quoted 8 lines
I guess we should. The question is, should we do that unconditionally or should we try to optimize thins with something like:
if (!virt_addr_valid(xfer->buf) || object_is_on_stack(xfer->buf)) /* Alloc bounce buf. */ else /* Use provided buf. */
There may be too many cases that we need to handle here that are not DMA capable. To be on the safe side, I'd probably always copy all data that is not a multiple of fully aligned cache lines, as well as pointers that fails to meet some other requirements (stack, vmalloc, kmap, ...)
Arnd
PATCH v9 7/9 dt-bindings: i3c: Document Cadence I3C master bindings
In reply to Boris BrezillonDocument Cadence I3C master DT bindings.
---
Changes in v9:
- Add Arnd's R-b
Changes in v8:
- None
Changes in v7:
- None
Changes in v6:
- None
Changes in v5:
- Add Rob's R-b
Changes in v4:
- Fix example to match the new representation
--- .../bindings/i3c/cdns,i3c-master.txt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/i3c/cdns,i3c-master.txt
Documentation/devicetree/bindings/i3c/cdns,i3c-master.txt new file +44 -0
@@ -0,0 +1,44 @@ +Bindings for cadence I3C master block +===================================== + +Required properties: +-------------------- +- compatible: shall be "cdns,i3c-master" +- clocks: shall reference the pclk and sysclk +- clock-names: shall contain "pclk" and "sysclk" +- interrupts: the interrupt line connected to this I3C master +- reg: I3C master registers + +Mandatory properties defined by the generic binding (see +Documentation/devicetree/bindings/i3c/i3c.txt for more details): + +- #address-cells: shall be set to 1 +- #size-cells: shall be set to 0 + +Optional properties defined by the generic binding (see +Documentation/devicetree/bindings/i3c/i3c.txt for more details): + +- i2c-scl-hz +- i3c-scl-hz + +I3C device connected on the bus follow the generic description (see +Documentation/devicetree/bindings/i3c/i3c.txt for more details). + +Example: + + i3c-master@0d040000 { + compatible = "cdns,i3c-master"; + clocks = <&coreclock>, <&i3csysclock>; + clock-names = "pclk", "sysclk"; + interrupts = <3 0>; + reg = <0x0d040000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + i2c-scl-hz = <100000>; + + nunchuk: nunchuk@52 { + compatible = "nintendo,nunchuk"; + reg = <0x52 0x80000010 0>; + }; + }; +
Signature · 1 line
2.17.1
PATCH v9 8/9 gpio: Add a driver for Cadence I3C GPIO expander
In reply to Boris BrezillonAdd a driver for Cadence I3C GPIO expander.
---
Changes in v9:
- None
Changes in v8:
- None
Changes in v7:
- None
Changes in v6:
- Use kmalloc_array() instead of kmalloc(N * sizeof(X))
- Add Linus' ack
Changes in v5:
- Use the !! operator to return 0 or 1 in cdns_i3c_gpio_get_direction()
- Use a scratch buffer to make sure the buffers passed to i3c_device_do_priv_xfers() are DMA-able
- Fix errors reported by checkpatch
Changes in v4:
- none
Changes in v3:
- new
--- drivers/gpio/Kconfig | 11 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-cdns-i3c.c | 411 +++++++++++++++++++++++++++++++++++ 3 files changed, 423 insertions(+) create mode 100644 drivers/gpio/gpio-cdns-i3c.c
drivers/gpio/Kconfig +11 -0
@@ -908,6 +908,17 @@ config GPIO_TS4900 endmenu +menu "I3C GPIO expanders" + depends on I3C + +config GPIO_CDNS_I3C + tristate "Cadence I3C GPIO expander" + select GPIOLIB_IRQCHIP + help + Say yes here to enabled the driver for Cadence I3C GPIO expander. + +endmenu + menu "MFD GPIO expanders" config GPIO_ADP5520
drivers/gpio/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o +obj-$(CONFIG_GPIO_CDNS_I3C) += gpio-cdns-i3c.o obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o obj-$(CONFIG_GPIO_CRYSTAL_COVE) += gpio-crystalcove.o
drivers/gpio/gpio-cdns-i3c.c new file +411 -0
411 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v9 9/9 dt-bindings: gpio: Add bindings for Cadence I3C gpio expander
In reply to Boris BrezillonDocument the Cadence I3C gpio expander bindings.
---
Changes in v9:
- Add Linus R-b
Changes in v8:
- None
Changes in v7:
- None
Changes in v6:
- None
Changes in v5:
- Add Rob's R-b
Changes in v4:
- Use GPIO_ and IRQ_TYPE_ macros instead of raw numbers
- Fix the unit-address in the example
--- .../bindings/gpio/gpio-cdns-i3c.txt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-cdns-i3c.txt
Documentation/devicetree/bindings/gpio/gpio-cdns-i3c.txt new file +39 -0
@@ -0,0 +1,39 @@ +* Cadence I3C GPIO expander + +The Cadence I3C GPIO expander provides 8 GPIOs controllable over I3C. +This GPIOs can be configured in output or input mode and if they are in input +mode they can generate IBIs (In Band Interrupts). + +Required properties for GPIO node: +- reg : 3 cells encoding the I3C static address (none in our case) and the I3C + Provisional ID. See Documentation/devicetree/bindings/i3c/i3c.txt for + more details. + Should be <0x0 0x392 0x0>. +- gpio-controller : Marks the device node as a gpio controller. +- #gpio-cells : Should be two. The first cell is the pin number and + the second cell is used to specify the gpio polarity (GPIO_ACTIVE_HIGH or + GPIO_ACTIVE_LOW) +- interrupt-controller: Marks the device node as an interrupt controller. +- #interrupt-cells : Should be 2. The first cell is the GPIO number. + The second cell is used to specify trigger type and level flags. + The following trigger types are accepted (see + <dt-bindings/interrupt-controller/irq.h> for their definition): + IRQ_TYPE_EDGE_RISING + IRQ_TYPE_EDGE_FALLING + IRQ_TYPE_EDGE_BOTH + IRQ_TYPE_LEVEL_HIGH + IRQ_TYPE_LEVEL_LOW + +Example: + + i3c-master@xxx { + ... + i3c_gpio_expander: gpio@0,39200000000 { + reg = <0 0x392 0x0>; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + ... + };
Signature · 1 line
2.17.1