xref: /OK3568_Linux_fs/kernel/Documentation/core-api/debugging-via-ohci1394.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===========================================================================
2*4882a593SmuzhiyunUsing physical DMA provided by OHCI-1394 FireWire controllers for debugging
3*4882a593Smuzhiyun===========================================================================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunIntroduction
6*4882a593Smuzhiyun------------
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunBasically all FireWire controllers which are in use today are compliant
9*4882a593Smuzhiyunto the OHCI-1394 specification which defines the controller to be a PCI
10*4882a593Smuzhiyunbus master which uses DMA to offload data transfers from the CPU and has
11*4882a593Smuzhiyuna "Physical Response Unit" which executes specific requests by employing
12*4882a593SmuzhiyunPCI-Bus master DMA after applying filters defined by the OHCI-1394 driver.
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunOnce properly configured, remote machines can send these requests to
15*4882a593Smuzhiyunask the OHCI-1394 controller to perform read and write requests on
16*4882a593Smuzhiyunphysical system memory and, for read requests, send the result of
17*4882a593Smuzhiyunthe physical memory read back to the requester.
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunWith that, it is possible to debug issues by reading interesting memory
20*4882a593Smuzhiyunlocations such as buffers like the printk buffer or the process table.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunRetrieving a full system memory dump is also possible over the FireWire,
23*4882a593Smuzhiyunusing data transfer rates in the order of 10MB/s or more.
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunWith most FireWire controllers, memory access is limited to the low 4 GB
26*4882a593Smuzhiyunof physical address space.  This can be a problem on IA64 machines where
27*4882a593Smuzhiyunmemory is located mostly above that limit, but it is rarely a problem on
28*4882a593Smuzhiyunmore common hardware such as x86, x86-64 and PowerPC.
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunAt least LSI FW643e and FW643e2 controllers are known to support access to
31*4882a593Smuzhiyunphysical addresses above 4 GB, but this feature is currently not enabled by
32*4882a593SmuzhiyunLinux.
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunTogether with a early initialization of the OHCI-1394 controller for debugging,
35*4882a593Smuzhiyunthis facility proved most useful for examining long debugs logs in the printk
36*4882a593Smuzhiyunbuffer on to debug early boot problems in areas like ACPI where the system
37*4882a593Smuzhiyunfails to boot and other means for debugging (serial port) are either not
38*4882a593Smuzhiyunavailable (notebooks) or too slow for extensive debug information (like ACPI).
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunDrivers
41*4882a593Smuzhiyun-------
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunThe firewire-ohci driver in drivers/firewire uses filtered physical
44*4882a593SmuzhiyunDMA by default, which is more secure but not suitable for remote debugging.
45*4882a593SmuzhiyunPass the remote_dma=1 parameter to the driver to get unfiltered physical DMA.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunBecause the firewire-ohci driver depends on the PCI enumeration to be
48*4882a593Smuzhiyuncompleted, an initialization routine which runs pretty early has been
49*4882a593Smuzhiyunimplemented for x86.  This routine runs long before console_init() can be
50*4882a593Smuzhiyuncalled, i.e. before the printk buffer appears on the console.
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunTo activate it, enable CONFIG_PROVIDE_OHCI1394_DMA_INIT (Kernel hacking menu:
53*4882a593SmuzhiyunRemote debugging over FireWire early on boot) and pass the parameter
54*4882a593Smuzhiyun"ohci1394_dma=early" to the recompiled kernel on boot.
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunTools
57*4882a593Smuzhiyun-----
58*4882a593Smuzhiyun
59*4882a593Smuzhiyunfirescope - Originally developed by Benjamin Herrenschmidt, Andi Kleen ported
60*4882a593Smuzhiyunit from PowerPC to x86 and x86_64 and added functionality, firescope can now
61*4882a593Smuzhiyunbe used to view the printk buffer of a remote machine, even with live update.
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunBernhard Kaindl enhanced firescope to support accessing 64-bit machines
64*4882a593Smuzhiyunfrom 32-bit firescope and vice versa:
65*4882a593Smuzhiyun- http://v3.sk/~lkundrak/firescope/
66*4882a593Smuzhiyun
67*4882a593Smuzhiyunand he implemented fast system dump (alpha version - read README.txt):
68*4882a593Smuzhiyun- http://halobates.de/firewire/firedump-0.1.tar.bz2
69*4882a593Smuzhiyun
70*4882a593SmuzhiyunThere is also a gdb proxy for firewire which allows to use gdb to access
71*4882a593Smuzhiyundata which can be referenced from symbols found by gdb in vmlinux:
72*4882a593Smuzhiyun- http://halobates.de/firewire/fireproxy-0.33.tar.bz2
73*4882a593Smuzhiyun
74*4882a593SmuzhiyunThe latest version of this gdb proxy (fireproxy-0.34) can communicate (not
75*4882a593Smuzhiyunyet stable) with kgdb over an memory-based communication module (kgdbom).
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunGetting Started
78*4882a593Smuzhiyun---------------
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunThe OHCI-1394 specification regulates that the OHCI-1394 controller must
81*4882a593Smuzhiyundisable all physical DMA on each bus reset.
82*4882a593Smuzhiyun
83*4882a593SmuzhiyunThis means that if you want to debug an issue in a system state where
84*4882a593Smuzhiyuninterrupts are disabled and where no polling of the OHCI-1394 controller
85*4882a593Smuzhiyunfor bus resets takes place, you have to establish any FireWire cable
86*4882a593Smuzhiyunconnections and fully initialize all FireWire hardware __before__ the
87*4882a593Smuzhiyunsystem enters such state.
88*4882a593Smuzhiyun
89*4882a593SmuzhiyunStep-by-step instructions for using firescope with early OHCI initialization:
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun1) Verify that your hardware is supported:
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun   Load the firewire-ohci module and check your kernel logs.
94*4882a593Smuzhiyun   You should see a line similar to::
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun     firewire_ohci 0000:15:00.1: added OHCI v1.0 device as card 2, 4 IR + 4 IT
97*4882a593Smuzhiyun     ... contexts, quirks 0x11
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun   when loading the driver. If you have no supported controller, many PCI,
100*4882a593Smuzhiyun   CardBus and even some Express cards which are fully compliant to OHCI-1394
101*4882a593Smuzhiyun   specification are available. If it requires no driver for Windows operating
102*4882a593Smuzhiyun   systems, it most likely is. Only specialized shops have cards which are not
103*4882a593Smuzhiyun   compliant, they are based on TI PCILynx chips and require drivers for Windows
104*4882a593Smuzhiyun   operating systems.
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun   The mentioned kernel log message contains the string "physUB" if the
107*4882a593Smuzhiyun   controller implements a writable Physical Upper Bound register.  This is
108*4882a593Smuzhiyun   required for physical DMA above 4 GB (but not utilized by Linux yet).
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun2) Establish a working FireWire cable connection:
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun   Any FireWire cable, as long at it provides electrically and mechanically
113*4882a593Smuzhiyun   stable connection and has matching connectors (there are small 4-pin and
114*4882a593Smuzhiyun   large 6-pin FireWire ports) will do.
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun   If an driver is running on both machines you should see a line like::
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun     firewire_core 0000:15:00.1: created device fw1: GUID 00061b0020105917, S400
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun   on both machines in the kernel log when the cable is plugged in
121*4882a593Smuzhiyun   and connects the two machines.
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun3) Test physical DMA using firescope:
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun   On the debug host, make sure that /dev/fw* is accessible,
126*4882a593Smuzhiyun   then start firescope::
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun	$ firescope
129*4882a593Smuzhiyun	Port 0 (/dev/fw1) opened, 2 nodes detected
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun	FireScope
132*4882a593Smuzhiyun	---------
133*4882a593Smuzhiyun	Target : <unspecified>
134*4882a593Smuzhiyun	Gen    : 1
135*4882a593Smuzhiyun	[Ctrl-T] choose target
136*4882a593Smuzhiyun	[Ctrl-H] this menu
137*4882a593Smuzhiyun	[Ctrl-Q] quit
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun    ------> Press Ctrl-T now, the output should be similar to:
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun	2 nodes available, local node is: 0
142*4882a593Smuzhiyun	 0: ffc0, uuid: 00000000 00000000 [LOCAL]
143*4882a593Smuzhiyun	 1: ffc1, uuid: 00279000 ba4bb801
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun   Besides the [LOCAL] node, it must show another node without error message.
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun4) Prepare for debugging with early OHCI-1394 initialization:
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun   4.1) Kernel compilation and installation on debug target
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun   Compile the kernel to be debugged with CONFIG_PROVIDE_OHCI1394_DMA_INIT
152*4882a593Smuzhiyun   (Kernel hacking: Provide code for enabling DMA over FireWire early on boot)
153*4882a593Smuzhiyun   enabled and install it on the machine to be debugged (debug target).
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun   4.2) Transfer the System.map of the debugged kernel to the debug host
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun   Copy the System.map of the kernel be debugged to the debug host (the host
158*4882a593Smuzhiyun   which is connected to the debugged machine over the FireWire cable).
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun5) Retrieving the printk buffer contents:
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun   With the FireWire cable connected, the OHCI-1394 driver on the debugging
163*4882a593Smuzhiyun   host loaded, reboot the debugged machine, booting the kernel which has
164*4882a593Smuzhiyun   CONFIG_PROVIDE_OHCI1394_DMA_INIT enabled, with the option ohci1394_dma=early.
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun   Then, on the debugging host, run firescope, for example by using -A::
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun	firescope -A System.map-of-debug-target-kernel
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun   Note: -A automatically attaches to the first non-local node. It only works
171*4882a593Smuzhiyun   reliably if only connected two machines are connected using FireWire.
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun   After having attached to the debug target, press Ctrl-D to view the
174*4882a593Smuzhiyun   complete printk buffer or Ctrl-U to enter auto update mode and get an
175*4882a593Smuzhiyun   updated live view of recent kernel messages logged on the debug target.
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun   Call "firescope -h" to get more information on firescope's options.
178*4882a593Smuzhiyun
179*4882a593SmuzhiyunNotes
180*4882a593Smuzhiyun-----
181*4882a593Smuzhiyun
182*4882a593SmuzhiyunDocumentation and specifications: http://halobates.de/firewire/
183*4882a593Smuzhiyun
184*4882a593SmuzhiyunFireWire is a trademark of Apple Inc. - for more information please refer to:
185*4882a593Smuzhiyunhttps://en.wikipedia.org/wiki/FireWire
186