[bootlin/training-materials updates] master: kernel-device-model: Try to modernize the slides a bit (7dd58b41)
Miquel Raynal
miquel.raynal at bootlin.com
Sat Jan 14 00:07:03 CET 2023
Repository : https://github.com/bootlin/training-materials
On branch : master
Link : https://github.com/bootlin/training-materials/commit/7dd58b4140ee7d43ab042894a3478383f265a590
>---------------------------------------------------------------
commit 7dd58b4140ee7d43ab042894a3478383f265a590
Author: Miquel Raynal <miquel.raynal at bootlin.com>
Date: Sat Jan 14 00:04:54 2023 +0100
kernel-device-model: Try to modernize the slides a bit
Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
>---------------------------------------------------------------
7dd58b4140ee7d43ab042894a3478383f265a590
slides/kernel-device-model/kernel-device-model.tex | 209 ++++-----------------
1 file changed, 36 insertions(+), 173 deletions(-)
diff --git a/slides/kernel-device-model/kernel-device-model.tex b/slides/kernel-device-model/kernel-device-model.tex
index 383e260e..1586bd3a 100644
--- a/slides/kernel-device-model/kernel-device-model.tex
+++ b/slides/kernel-device-model/kernel-device-model.tex
@@ -446,112 +446,57 @@ module_platform_driver(serial_imx_driver);
\end{frame}
\begin{frame}[fragile]
- \frametitle{Platform Device Instantiation: old style (1/2)}
+ \frametitle{Platform device instantiation}
\begin{itemize}
\item As platform devices cannot be detected dynamically, they are
defined statically
\begin{itemize}
- \item By direct instantiation of \kstruct{platform_device}
- structures, as done on a few old ARM platforms. Definition done in
- the board-specific or SoC specific code.
- \item By using a \emph{device tree}, as done on Power PC (and on
- most ARM platforms) from which \kstruct{platform_device}
- structures are created
+ \item Legacy way: by direct instantiation of \kstruct{platform_device}
+ structures, as done on a few old ARM platforms. The device was
+ part of a list, and the list of devices was added to the system
+ during board initialization.
+ \item Current way: By parsing an "external" description, like a
+ \emph{device tree} on most embedded platforms today, from which
+ \kstruct{platform_device} structures are created.
\end{itemize}
- \item Example on ARM, where the instantiation was done in
- \kfileversion{arch/arm/mach-imx/mx1ads.c}{2.6.30}
- \begin{block}{}
-\begin{minted}[fontsize=\scriptsize]{c}
-static struct platform_device imx_uart1_device = {
- .name = "imx-uart",
- .id = 0,
- .num_resources = ARRAY_SIZE(imx_uart1_resources),
- .resource = imx_uart1_resources,
- .dev = {
- .platform_data = &uart_pdata,
- }
-};
-\end{minted}
-\end{block}
-\end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Platform device instantiation: old style (2/2)}
- \begin{itemize}
- \item The device was part of a list
- \begin{block}{}
- \begin{minted}[fontsize=\scriptsize]{c}
-static struct platform_device *devices[] __initdata = {
- &cs89x0_device,
- &imx_uart1_device,
- &imx_uart2_device,
-};
- \end{minted}
- \end{block}
- \item And the list of devices was added to the system during
- board initialization
- \begin{block}{}
- \begin{minted}[fontsize=\scriptsize]{c}
-static void __init mx1ads_init(void)
-{
- [...]
- platform_add_devices(devices, ARRAY_SIZE(devices));
-}
-
-MACHINE_START(MX1ADS, "Freescale MX1ADS")
- [...]
- .init_machine = mx1ads_init,
-MACHINE_END
- \end{minted}
- \end{block}
\end{itemize}
\end{frame}
\begin{frame}
- \frametitle{The Resource Mechanism}
+ \frametitle{Using additional hardware resources}
\begin{itemize}
- \item Each device managed by a particular driver typically uses
- different hardware resources: addresses for the I/O registers, DMA
- channels, IRQ lines, etc.
- \item Such information can be represented using
- \kstruct{resource}, and an array of \kstruct{resource} is
- associated to a \kstruct{platform_device}
- \item Allows a driver to be instantiated for multiple devices
- functioning similarly, but with different addresses, IRQs, etc.
+ \item Regular DT descriptions contain many information, including
+ phandles (pointers) towards additional hardware blocks or hardware
+ details which cannot be discovered.
+ \begin{itemize}
+ \item Some of them are available through a generic array of resourses,
+ like addresses for the I/O registers and IRQ lines:
+ \begin{itemize}
+ \item Such information can be represented using \kstruct{resource},
+ and an array of \kstruct{resource} is associated to each
+ \kstruct{platform_device}.
+ \end{itemize}
+ \item Common information/dependencies are parsed by the relevant
+ subsystems, like clocks, GPIOs, or DMA channels:
+ \begin{itemize}
+ \item Each subsystem is responsible of instantiating its
+ components, and offering an API to retrieve these objects and
+ use them from device drivers.
+ \end{itemize}
+ \item Specific information might be directly be retrieved by
+ device drivers, through (expensive) direct DT lookups (old drivers
+ use \kstruct{platform_data}).
+ \end{itemize}
+ \item All these methods allow the same driver to be used with
+ multiple devices functioning similarly, but with different
+ addresses, IRQs, etc.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
- \frametitle{Declaring resources (old style)}
- \begin{block}{}
- \begin{minted}[fontsize=\footnotesize]{c}
-static struct resource imx_uart1_resources[] = {
- [0] = {
- .start = 0x00206000,
- .end = 0x002060FF,
- .flags = IORESOURCE_MEM,
- },
- [1] = {
- .start = (UART1_MINT_RX),
- .end = (UART1_MINT_RX),
- .flags = IORESOURCE_IRQ,
- },
-};
-\end{minted}
-\end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Using Resources (old style)}
+ \frametitle{Using Resources}
\begin{itemize}
- \item When a \kstruct{platform_device} was added to the system using
- \kfunc{platform_add_devices}, the \code{probe()} method of the
- platform driver was called
- \item This method is responsible for initializing the hardware,
- registering the device to the proper framework (in our case, the
- serial driver framework)
- \item The platform driver has access to the I/O resources:
+ \item The platform driver has access to the resources:
\begin{block}{}
\begin{minted}[fontsize=\footnotesize]{c}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -559,88 +504,6 @@ base = ioremap(res->start, PAGE_SIZE);
sport->rxirq = platform_get_irq(pdev, 0);
\end{minted}
\end{block}
- \end{itemize}
-\end{frame}
-
-\begin{frame}
- \frametitle{platform\_data Mechanism (old style)}
- \begin{itemize}
- \item In addition to the well-defined resources, many drivers
- require driver-specific information for each platform device
- \item Such information could be passed using the \code{platform_data}
- field of \kstruct{device} (from which
- \kstruct{platform_device} inherits)
- \item As it is a \code{void *} pointer, it could be used to pass any
- type of information.
- \begin{itemize}
- \item Typically, each driver defines a structure to pass
- information through \kstruct{platform_data}
- \end{itemize}
- \end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{platform\_data example 1/2}
- \begin{itemize}
- \item The i.MX serial port driver defines the following structure to
- be passed through \kstruct{platform_data}
- \begin{block}{}
- \begin{minted}[fontsize=\footnotesize]{c}
-struct imxuart_platform_data {
- int (*init)(struct platform_device *pdev);
- void (*exit)(struct platform_device *pdev);
- unsigned int flags;
- void (*irda_enable)(int enable);
- unsigned int irda_inv_rx:1;
- unsigned int irda_inv_tx:1;
- unsigned short transceiver_delay;
-};
- \end{minted}
- \end{block}
- \item The MX1ADS board code instantiated such a structure
- \begin{block}{}
- \begin{minted}[fontsize=\footnotesize]{c}
-static struct imxuart_platform_data uart_pdata = {
- .flags = IMXUART_HAVE_RTSCTS,
-};
- \end{minted}
- \end{block}
- \end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{platform\_data Example 2/2}
- \begin{itemize}
- \item The \code{uart_pdata} structure was associated to the
- \kstruct{platform_device} structure in the MX1ADS board file (the
- real code was slightly more complicated)
- \begin{block}{}
- \begin{minted}[fontsize=\scriptsize]{c}
-struct platform_device mx1ads_uart1 = {
- .name = "imx-uart",
- .dev {
- .platform_data = &uart_pdata,
- },
- .resource = imx_uart1_resources,
- [...]
-};
- \end{minted}
- \end{block}
- \item The driver can access the platform data:
- \begin{block}{}
- \begin{minted}[fontsize=\scriptsize]{c}
-static int serial_imx_probe(struct platform_device *pdev)
-{
- struct imxuart_platform_data *pdata;
- pdata = pdev->dev.platform_data;
- if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS))
- sport->have_rtscts = 1;
- [...]
- \end{minted}
- \end{block}
-\end{itemize}
-\end{frame}
-
\begin{frame}
\frametitle{Device Tree}
\begin{itemize}
More information about the training-materials-updates
mailing list