18c2ecf20Sopenharmony_ci===========================================================================
28c2ecf20Sopenharmony_ciUsing physical DMA provided by OHCI-1394 FireWire controllers for debugging
38c2ecf20Sopenharmony_ci===========================================================================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciIntroduction
68c2ecf20Sopenharmony_ci------------
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciBasically all FireWire controllers which are in use today are compliant
98c2ecf20Sopenharmony_cito the OHCI-1394 specification which defines the controller to be a PCI
108c2ecf20Sopenharmony_cibus master which uses DMA to offload data transfers from the CPU and has
118c2ecf20Sopenharmony_cia "Physical Response Unit" which executes specific requests by employing
128c2ecf20Sopenharmony_ciPCI-Bus master DMA after applying filters defined by the OHCI-1394 driver.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciOnce properly configured, remote machines can send these requests to
158c2ecf20Sopenharmony_ciask the OHCI-1394 controller to perform read and write requests on
168c2ecf20Sopenharmony_ciphysical system memory and, for read requests, send the result of
178c2ecf20Sopenharmony_cithe physical memory read back to the requester.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciWith that, it is possible to debug issues by reading interesting memory
208c2ecf20Sopenharmony_cilocations such as buffers like the printk buffer or the process table.
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciRetrieving a full system memory dump is also possible over the FireWire,
238c2ecf20Sopenharmony_ciusing data transfer rates in the order of 10MB/s or more.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciWith most FireWire controllers, memory access is limited to the low 4 GB
268c2ecf20Sopenharmony_ciof physical address space.  This can be a problem on IA64 machines where
278c2ecf20Sopenharmony_cimemory is located mostly above that limit, but it is rarely a problem on
288c2ecf20Sopenharmony_cimore common hardware such as x86, x86-64 and PowerPC.
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciAt least LSI FW643e and FW643e2 controllers are known to support access to
318c2ecf20Sopenharmony_ciphysical addresses above 4 GB, but this feature is currently not enabled by
328c2ecf20Sopenharmony_ciLinux.
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciTogether with a early initialization of the OHCI-1394 controller for debugging,
358c2ecf20Sopenharmony_cithis facility proved most useful for examining long debugs logs in the printk
368c2ecf20Sopenharmony_cibuffer on to debug early boot problems in areas like ACPI where the system
378c2ecf20Sopenharmony_cifails to boot and other means for debugging (serial port) are either not
388c2ecf20Sopenharmony_ciavailable (notebooks) or too slow for extensive debug information (like ACPI).
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciDrivers
418c2ecf20Sopenharmony_ci-------
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciThe firewire-ohci driver in drivers/firewire uses filtered physical
448c2ecf20Sopenharmony_ciDMA by default, which is more secure but not suitable for remote debugging.
458c2ecf20Sopenharmony_ciPass the remote_dma=1 parameter to the driver to get unfiltered physical DMA.
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciBecause the firewire-ohci driver depends on the PCI enumeration to be
488c2ecf20Sopenharmony_cicompleted, an initialization routine which runs pretty early has been
498c2ecf20Sopenharmony_ciimplemented for x86.  This routine runs long before console_init() can be
508c2ecf20Sopenharmony_cicalled, i.e. before the printk buffer appears on the console.
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciTo activate it, enable CONFIG_PROVIDE_OHCI1394_DMA_INIT (Kernel hacking menu:
538c2ecf20Sopenharmony_ciRemote debugging over FireWire early on boot) and pass the parameter
548c2ecf20Sopenharmony_ci"ohci1394_dma=early" to the recompiled kernel on boot.
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciTools
578c2ecf20Sopenharmony_ci-----
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cifirescope - Originally developed by Benjamin Herrenschmidt, Andi Kleen ported
608c2ecf20Sopenharmony_ciit from PowerPC to x86 and x86_64 and added functionality, firescope can now
618c2ecf20Sopenharmony_cibe used to view the printk buffer of a remote machine, even with live update.
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ciBernhard Kaindl enhanced firescope to support accessing 64-bit machines
648c2ecf20Sopenharmony_cifrom 32-bit firescope and vice versa:
658c2ecf20Sopenharmony_ci- http://v3.sk/~lkundrak/firescope/
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciand he implemented fast system dump (alpha version - read README.txt):
688c2ecf20Sopenharmony_ci- http://halobates.de/firewire/firedump-0.1.tar.bz2
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciThere is also a gdb proxy for firewire which allows to use gdb to access
718c2ecf20Sopenharmony_cidata which can be referenced from symbols found by gdb in vmlinux:
728c2ecf20Sopenharmony_ci- http://halobates.de/firewire/fireproxy-0.33.tar.bz2
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ciThe latest version of this gdb proxy (fireproxy-0.34) can communicate (not
758c2ecf20Sopenharmony_ciyet stable) with kgdb over an memory-based communication module (kgdbom).
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciGetting Started
788c2ecf20Sopenharmony_ci---------------
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciThe OHCI-1394 specification regulates that the OHCI-1394 controller must
818c2ecf20Sopenharmony_cidisable all physical DMA on each bus reset.
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ciThis means that if you want to debug an issue in a system state where
848c2ecf20Sopenharmony_ciinterrupts are disabled and where no polling of the OHCI-1394 controller
858c2ecf20Sopenharmony_cifor bus resets takes place, you have to establish any FireWire cable
868c2ecf20Sopenharmony_ciconnections and fully initialize all FireWire hardware __before__ the
878c2ecf20Sopenharmony_cisystem enters such state.
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciStep-by-step instructions for using firescope with early OHCI initialization:
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci1) Verify that your hardware is supported:
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci   Load the firewire-ohci module and check your kernel logs.
948c2ecf20Sopenharmony_ci   You should see a line similar to::
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci     firewire_ohci 0000:15:00.1: added OHCI v1.0 device as card 2, 4 IR + 4 IT
978c2ecf20Sopenharmony_ci     ... contexts, quirks 0x11
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci   when loading the driver. If you have no supported controller, many PCI,
1008c2ecf20Sopenharmony_ci   CardBus and even some Express cards which are fully compliant to OHCI-1394
1018c2ecf20Sopenharmony_ci   specification are available. If it requires no driver for Windows operating
1028c2ecf20Sopenharmony_ci   systems, it most likely is. Only specialized shops have cards which are not
1038c2ecf20Sopenharmony_ci   compliant, they are based on TI PCILynx chips and require drivers for Windows
1048c2ecf20Sopenharmony_ci   operating systems.
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci   The mentioned kernel log message contains the string "physUB" if the
1078c2ecf20Sopenharmony_ci   controller implements a writable Physical Upper Bound register.  This is
1088c2ecf20Sopenharmony_ci   required for physical DMA above 4 GB (but not utilized by Linux yet).
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci2) Establish a working FireWire cable connection:
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci   Any FireWire cable, as long at it provides electrically and mechanically
1138c2ecf20Sopenharmony_ci   stable connection and has matching connectors (there are small 4-pin and
1148c2ecf20Sopenharmony_ci   large 6-pin FireWire ports) will do.
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci   If an driver is running on both machines you should see a line like::
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci     firewire_core 0000:15:00.1: created device fw1: GUID 00061b0020105917, S400
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci   on both machines in the kernel log when the cable is plugged in
1218c2ecf20Sopenharmony_ci   and connects the two machines.
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci3) Test physical DMA using firescope:
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci   On the debug host, make sure that /dev/fw* is accessible,
1268c2ecf20Sopenharmony_ci   then start firescope::
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	$ firescope
1298c2ecf20Sopenharmony_ci	Port 0 (/dev/fw1) opened, 2 nodes detected
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	FireScope
1328c2ecf20Sopenharmony_ci	---------
1338c2ecf20Sopenharmony_ci	Target : <unspecified>
1348c2ecf20Sopenharmony_ci	Gen    : 1
1358c2ecf20Sopenharmony_ci	[Ctrl-T] choose target
1368c2ecf20Sopenharmony_ci	[Ctrl-H] this menu
1378c2ecf20Sopenharmony_ci	[Ctrl-Q] quit
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci    ------> Press Ctrl-T now, the output should be similar to:
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	2 nodes available, local node is: 0
1428c2ecf20Sopenharmony_ci	 0: ffc0, uuid: 00000000 00000000 [LOCAL]
1438c2ecf20Sopenharmony_ci	 1: ffc1, uuid: 00279000 ba4bb801
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci   Besides the [LOCAL] node, it must show another node without error message.
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci4) Prepare for debugging with early OHCI-1394 initialization:
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci   4.1) Kernel compilation and installation on debug target
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci   Compile the kernel to be debugged with CONFIG_PROVIDE_OHCI1394_DMA_INIT
1528c2ecf20Sopenharmony_ci   (Kernel hacking: Provide code for enabling DMA over FireWire early on boot)
1538c2ecf20Sopenharmony_ci   enabled and install it on the machine to be debugged (debug target).
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci   4.2) Transfer the System.map of the debugged kernel to the debug host
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci   Copy the System.map of the kernel be debugged to the debug host (the host
1588c2ecf20Sopenharmony_ci   which is connected to the debugged machine over the FireWire cable).
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci5) Retrieving the printk buffer contents:
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci   With the FireWire cable connected, the OHCI-1394 driver on the debugging
1638c2ecf20Sopenharmony_ci   host loaded, reboot the debugged machine, booting the kernel which has
1648c2ecf20Sopenharmony_ci   CONFIG_PROVIDE_OHCI1394_DMA_INIT enabled, with the option ohci1394_dma=early.
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci   Then, on the debugging host, run firescope, for example by using -A::
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	firescope -A System.map-of-debug-target-kernel
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci   Note: -A automatically attaches to the first non-local node. It only works
1718c2ecf20Sopenharmony_ci   reliably if only connected two machines are connected using FireWire.
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci   After having attached to the debug target, press Ctrl-D to view the
1748c2ecf20Sopenharmony_ci   complete printk buffer or Ctrl-U to enter auto update mode and get an
1758c2ecf20Sopenharmony_ci   updated live view of recent kernel messages logged on the debug target.
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci   Call "firescope -h" to get more information on firescope's options.
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ciNotes
1808c2ecf20Sopenharmony_ci-----
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ciDocumentation and specifications: http://halobates.de/firewire/
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ciFireWire is a trademark of Apple Inc. - for more information please refer to:
1858c2ecf20Sopenharmony_cihttps://en.wikipedia.org/wiki/FireWire
186