xref: /linux/Documentation/arch/sh/new-machine.rst (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1*d47a97bdSJonathan Corbet.. SPDX-License-Identifier: GPL-2.0
2*d47a97bdSJonathan Corbet
3*d47a97bdSJonathan Corbet=============================
4*d47a97bdSJonathan CorbetAdding a new board to LinuxSH
5*d47a97bdSJonathan Corbet=============================
6*d47a97bdSJonathan Corbet
7*d47a97bdSJonathan Corbet               Paul Mundt <lethal@linux-sh.org>
8*d47a97bdSJonathan Corbet
9*d47a97bdSJonathan CorbetThis document attempts to outline what steps are necessary to add support
10*d47a97bdSJonathan Corbetfor new boards to the LinuxSH port under the new 2.5 and 2.6 kernels. This
11*d47a97bdSJonathan Corbetalso attempts to outline some of the noticeable changes between the 2.4
12*d47a97bdSJonathan Corbetand the 2.5/2.6 SH backend.
13*d47a97bdSJonathan Corbet
14*d47a97bdSJonathan Corbet1. New Directory Structure
15*d47a97bdSJonathan Corbet==========================
16*d47a97bdSJonathan Corbet
17*d47a97bdSJonathan CorbetThe first thing to note is the new directory structure. Under 2.4, most
18*d47a97bdSJonathan Corbetof the board-specific code (with the exception of stboards) ended up
19*d47a97bdSJonathan Corbetin arch/sh/kernel/ directly, with board-specific headers ending up in
20*d47a97bdSJonathan Corbetinclude/asm-sh/. For the new kernel, things are broken out by board type,
21*d47a97bdSJonathan Corbetcompanion chip type, and CPU type. Looking at a tree view of this directory
22*d47a97bdSJonathan Corbethierarchy looks like the following:
23*d47a97bdSJonathan Corbet
24*d47a97bdSJonathan CorbetBoard-specific code::
25*d47a97bdSJonathan Corbet
26*d47a97bdSJonathan Corbet    .
27*d47a97bdSJonathan Corbet    |-- arch
28*d47a97bdSJonathan Corbet    |   `-- sh
29*d47a97bdSJonathan Corbet    |       `-- boards
30*d47a97bdSJonathan Corbet    |           |-- adx
31*d47a97bdSJonathan Corbet    |           |   `-- board-specific files
32*d47a97bdSJonathan Corbet    |           |-- bigsur
33*d47a97bdSJonathan Corbet    |           |   `-- board-specific files
34*d47a97bdSJonathan Corbet    |           |
35*d47a97bdSJonathan Corbet    |           ... more boards here ...
36*d47a97bdSJonathan Corbet    |
37*d47a97bdSJonathan Corbet    `-- include
38*d47a97bdSJonathan Corbet	`-- asm-sh
39*d47a97bdSJonathan Corbet	    |-- adx
40*d47a97bdSJonathan Corbet	    |   `-- board-specific headers
41*d47a97bdSJonathan Corbet	    |-- bigsur
42*d47a97bdSJonathan Corbet	    |   `-- board-specific headers
43*d47a97bdSJonathan Corbet	    |
44*d47a97bdSJonathan Corbet	    .. more boards here ...
45*d47a97bdSJonathan Corbet
46*d47a97bdSJonathan CorbetNext, for companion chips::
47*d47a97bdSJonathan Corbet
48*d47a97bdSJonathan Corbet    .
49*d47a97bdSJonathan Corbet    `-- arch
50*d47a97bdSJonathan Corbet	`-- sh
51*d47a97bdSJonathan Corbet	    `-- cchips
52*d47a97bdSJonathan Corbet		`-- hd6446x
53*d47a97bdSJonathan Corbet		    `-- hd64461
54*d47a97bdSJonathan Corbet			`-- cchip-specific files
55*d47a97bdSJonathan Corbet
56*d47a97bdSJonathan Corbet... and so on. Headers for the companion chips are treated the same way as
57*d47a97bdSJonathan Corbetboard-specific headers. Thus, include/asm-sh/hd64461 is home to all of the
58*d47a97bdSJonathan Corbethd64461-specific headers.
59*d47a97bdSJonathan Corbet
60*d47a97bdSJonathan CorbetFinally, CPU family support is also abstracted::
61*d47a97bdSJonathan Corbet
62*d47a97bdSJonathan Corbet    .
63*d47a97bdSJonathan Corbet    |-- arch
64*d47a97bdSJonathan Corbet    |   `-- sh
65*d47a97bdSJonathan Corbet    |       |-- kernel
66*d47a97bdSJonathan Corbet    |       |   `-- cpu
67*d47a97bdSJonathan Corbet    |       |       |-- sh2
68*d47a97bdSJonathan Corbet    |       |       |   `-- SH-2 generic files
69*d47a97bdSJonathan Corbet    |       |       |-- sh3
70*d47a97bdSJonathan Corbet    |       |       |   `-- SH-3 generic files
71*d47a97bdSJonathan Corbet    |       |       `-- sh4
72*d47a97bdSJonathan Corbet    |       |           `-- SH-4 generic files
73*d47a97bdSJonathan Corbet    |       `-- mm
74*d47a97bdSJonathan Corbet    |           `-- This is also broken out per CPU family, so each family can
75*d47a97bdSJonathan Corbet    |               have their own set of cache/tlb functions.
76*d47a97bdSJonathan Corbet    |
77*d47a97bdSJonathan Corbet    `-- include
78*d47a97bdSJonathan Corbet	`-- asm-sh
79*d47a97bdSJonathan Corbet	    |-- cpu-sh2
80*d47a97bdSJonathan Corbet	    |   `-- SH-2 specific headers
81*d47a97bdSJonathan Corbet	    |-- cpu-sh3
82*d47a97bdSJonathan Corbet	    |   `-- SH-3 specific headers
83*d47a97bdSJonathan Corbet	    `-- cpu-sh4
84*d47a97bdSJonathan Corbet		`-- SH-4 specific headers
85*d47a97bdSJonathan Corbet
86*d47a97bdSJonathan CorbetIt should be noted that CPU subtypes are _not_ abstracted. Thus, these still
87*d47a97bdSJonathan Corbetneed to be dealt with by the CPU family specific code.
88*d47a97bdSJonathan Corbet
89*d47a97bdSJonathan Corbet2. Adding a New Board
90*d47a97bdSJonathan Corbet=====================
91*d47a97bdSJonathan Corbet
92*d47a97bdSJonathan CorbetThe first thing to determine is whether the board you are adding will be
93*d47a97bdSJonathan Corbetisolated, or whether it will be part of a family of boards that can mostly
94*d47a97bdSJonathan Corbetshare the same board-specific code with minor differences.
95*d47a97bdSJonathan Corbet
96*d47a97bdSJonathan CorbetIn the first case, this is just a matter of making a directory for your
97*d47a97bdSJonathan Corbetboard in arch/sh/boards/ and adding rules to hook your board in with the
98*d47a97bdSJonathan Corbetbuild system (more on this in the next section). However, for board families
99*d47a97bdSJonathan Corbetit makes more sense to have a common top-level arch/sh/boards/ directory
100*d47a97bdSJonathan Corbetand then populate that with sub-directories for each member of the family.
101*d47a97bdSJonathan CorbetBoth the Solution Engine and the hp6xx boards are an example of this.
102*d47a97bdSJonathan Corbet
103*d47a97bdSJonathan CorbetAfter you have setup your new arch/sh/boards/ directory, remember that you
104*d47a97bdSJonathan Corbetshould also add a directory in include/asm-sh for headers localized to this
105*d47a97bdSJonathan Corbetboard (if there are going to be more than one). In order to interoperate
106*d47a97bdSJonathan Corbetseamlessly with the build system, it's best to have this directory the same
107*d47a97bdSJonathan Corbetas the arch/sh/boards/ directory name, though if your board is again part of
108*d47a97bdSJonathan Corbeta family, the build system has ways of dealing with this (via incdir-y
109*d47a97bdSJonathan Corbetoverloading), and you can feel free to name the directory after the family
110*d47a97bdSJonathan Corbetmember itself.
111*d47a97bdSJonathan Corbet
112*d47a97bdSJonathan CorbetThere are a few things that each board is required to have, both in the
113*d47a97bdSJonathan Corbetarch/sh/boards and the include/asm-sh/ hierarchy. In order to better
114*d47a97bdSJonathan Corbetexplain this, we use some examples for adding an imaginary board. For
115*d47a97bdSJonathan Corbetsetup code, we're required at the very least to provide definitions for
116*d47a97bdSJonathan Corbetget_system_type() and platform_setup(). For our imaginary board, this
117*d47a97bdSJonathan Corbetmight look something like::
118*d47a97bdSJonathan Corbet
119*d47a97bdSJonathan Corbet    /*
120*d47a97bdSJonathan Corbet    * arch/sh/boards/vapor/setup.c - Setup code for imaginary board
121*d47a97bdSJonathan Corbet    */
122*d47a97bdSJonathan Corbet    #include <linux/init.h>
123*d47a97bdSJonathan Corbet
124*d47a97bdSJonathan Corbet    const char *get_system_type(void)
125*d47a97bdSJonathan Corbet    {
126*d47a97bdSJonathan Corbet	    return "FooTech Vaporboard";
127*d47a97bdSJonathan Corbet    }
128*d47a97bdSJonathan Corbet
129*d47a97bdSJonathan Corbet    int __init platform_setup(void)
130*d47a97bdSJonathan Corbet    {
131*d47a97bdSJonathan Corbet	    /*
132*d47a97bdSJonathan Corbet	    * If our hardware actually existed, we would do real
133*d47a97bdSJonathan Corbet	    * setup here. Though it's also sane to leave this empty
134*d47a97bdSJonathan Corbet	    * if there's no real init work that has to be done for
135*d47a97bdSJonathan Corbet	    * this board.
136*d47a97bdSJonathan Corbet	    */
137*d47a97bdSJonathan Corbet
138*d47a97bdSJonathan Corbet	    /* Start-up imaginary PCI ... */
139*d47a97bdSJonathan Corbet
140*d47a97bdSJonathan Corbet	    /* And whatever else ... */
141*d47a97bdSJonathan Corbet
142*d47a97bdSJonathan Corbet	    return 0;
143*d47a97bdSJonathan Corbet    }
144*d47a97bdSJonathan Corbet
145*d47a97bdSJonathan CorbetOur new imaginary board will also have to tie into the machvec in order for it
146*d47a97bdSJonathan Corbetto be of any use.
147*d47a97bdSJonathan Corbet
148*d47a97bdSJonathan Corbetmachvec functions fall into a number of categories:
149*d47a97bdSJonathan Corbet
150*d47a97bdSJonathan Corbet - I/O functions to IO memory (inb etc) and PCI/main memory (readb etc).
151*d47a97bdSJonathan Corbet - I/O mapping functions (ioport_map, ioport_unmap, etc).
152*d47a97bdSJonathan Corbet - a 'heartbeat' function.
153*d47a97bdSJonathan Corbet - PCI and IRQ initialization routines.
154*d47a97bdSJonathan Corbet - Consistent allocators (for boards that need special allocators,
155*d47a97bdSJonathan Corbet   particularly for allocating out of some board-specific SRAM for DMA
156*d47a97bdSJonathan Corbet   handles).
157*d47a97bdSJonathan Corbet
158*d47a97bdSJonathan CorbetThere are machvec functions added and removed over time, so always be sure to
159*d47a97bdSJonathan Corbetconsult include/asm-sh/machvec.h for the current state of the machvec.
160*d47a97bdSJonathan Corbet
161*d47a97bdSJonathan CorbetThe kernel will automatically wrap in generic routines for undefined function
162*d47a97bdSJonathan Corbetpointers in the machvec at boot time, as machvec functions are referenced
163*d47a97bdSJonathan Corbetunconditionally throughout most of the tree. Some boards have incredibly
164*d47a97bdSJonathan Corbetsparse machvecs (such as the dreamcast and sh03), whereas others must define
165*d47a97bdSJonathan Corbetvirtually everything (rts7751r2d).
166*d47a97bdSJonathan Corbet
167*d47a97bdSJonathan CorbetAdding a new machine is relatively trivial (using vapor as an example):
168*d47a97bdSJonathan Corbet
169*d47a97bdSJonathan CorbetIf the board-specific definitions are quite minimalistic, as is the case for
170*d47a97bdSJonathan Corbetthe vast majority of boards, simply having a single board-specific header is
171*d47a97bdSJonathan Corbetsufficient.
172*d47a97bdSJonathan Corbet
173*d47a97bdSJonathan Corbet - add a new file include/asm-sh/vapor.h which contains prototypes for
174*d47a97bdSJonathan Corbet   any machine specific IO functions prefixed with the machine name, for
175*d47a97bdSJonathan Corbet   example vapor_inb. These will be needed when filling out the machine
176*d47a97bdSJonathan Corbet   vector.
177*d47a97bdSJonathan Corbet
178*d47a97bdSJonathan Corbet   Note that these prototypes are generated automatically by setting
179*d47a97bdSJonathan Corbet   __IO_PREFIX to something sensible. A typical example would be::
180*d47a97bdSJonathan Corbet
181*d47a97bdSJonathan Corbet	#define __IO_PREFIX vapor
182*d47a97bdSJonathan Corbet	#include <asm/io_generic.h>
183*d47a97bdSJonathan Corbet
184*d47a97bdSJonathan Corbet   somewhere in the board-specific header. Any boards being ported that still
185*d47a97bdSJonathan Corbet   have a legacy io.h should remove it entirely and switch to the new model.
186*d47a97bdSJonathan Corbet
187*d47a97bdSJonathan Corbet - Add machine vector definitions to the board's setup.c. At a bare minimum,
188*d47a97bdSJonathan Corbet   this must be defined as something like::
189*d47a97bdSJonathan Corbet
190*d47a97bdSJonathan Corbet	struct sh_machine_vector mv_vapor __initmv = {
191*d47a97bdSJonathan Corbet		.mv_name = "vapor",
192*d47a97bdSJonathan Corbet	};
193*d47a97bdSJonathan Corbet	ALIAS_MV(vapor)
194*d47a97bdSJonathan Corbet
195*d47a97bdSJonathan Corbet - finally add a file arch/sh/boards/vapor/io.c, which contains definitions of
196*d47a97bdSJonathan Corbet   the machine specific io functions (if there are enough to warrant it).
197*d47a97bdSJonathan Corbet
198*d47a97bdSJonathan Corbet3. Hooking into the Build System
199*d47a97bdSJonathan Corbet================================
200*d47a97bdSJonathan Corbet
201*d47a97bdSJonathan CorbetNow that we have the corresponding directories setup, and all of the
202*d47a97bdSJonathan Corbetboard-specific code is in place, it's time to look at how to get the
203*d47a97bdSJonathan Corbetwhole mess to fit into the build system.
204*d47a97bdSJonathan Corbet
205*d47a97bdSJonathan CorbetLarge portions of the build system are now entirely dynamic, and merely
206*d47a97bdSJonathan Corbetrequire the proper entry here and there in order to get things done.
207*d47a97bdSJonathan Corbet
208*d47a97bdSJonathan CorbetThe first thing to do is to add an entry to arch/sh/Kconfig, under the
209*d47a97bdSJonathan Corbet"System type" menu::
210*d47a97bdSJonathan Corbet
211*d47a97bdSJonathan Corbet    config SH_VAPOR
212*d47a97bdSJonathan Corbet	    bool "Vapor"
213*d47a97bdSJonathan Corbet	    help
214*d47a97bdSJonathan Corbet	    select Vapor if configuring for a FooTech Vaporboard.
215*d47a97bdSJonathan Corbet
216*d47a97bdSJonathan Corbetnext, this has to be added into arch/sh/Makefile. All boards require a
217*d47a97bdSJonathan Corbetmachdir-y entry in order to be built. This entry needs to be the name of
218*d47a97bdSJonathan Corbetthe board directory as it appears in arch/sh/boards, even if it is in a
219*d47a97bdSJonathan Corbetsub-directory (in which case, all parent directories below arch/sh/boards/
220*d47a97bdSJonathan Corbetneed to be listed). For our new board, this entry can look like::
221*d47a97bdSJonathan Corbet
222*d47a97bdSJonathan Corbet    machdir-$(CONFIG_SH_VAPOR)	+= vapor
223*d47a97bdSJonathan Corbet
224*d47a97bdSJonathan Corbetprovided that we've placed everything in the arch/sh/boards/vapor/ directory.
225*d47a97bdSJonathan Corbet
226*d47a97bdSJonathan CorbetNext, the build system assumes that your include/asm-sh directory will also
227*d47a97bdSJonathan Corbetbe named the same. If this is not the case (as is the case with multiple
228*d47a97bdSJonathan Corbetboards belonging to a common family), then the directory name needs to be
229*d47a97bdSJonathan Corbetimplicitly appended to incdir-y. The existing code manages this for the
230*d47a97bdSJonathan CorbetSolution Engine and hp6xx boards, so see these for an example.
231*d47a97bdSJonathan Corbet
232*d47a97bdSJonathan CorbetOnce that is taken care of, it's time to add an entry for the mach type.
233*d47a97bdSJonathan CorbetThis is done by adding an entry to the end of the arch/sh/tools/mach-types
234*d47a97bdSJonathan Corbetlist. The method for doing this is self explanatory, and so we won't waste
235*d47a97bdSJonathan Corbetspace restating it here. After this is done, you will be able to use
236*d47a97bdSJonathan Corbetimplicit checks for your board if you need this somewhere throughout the
237*d47a97bdSJonathan Corbetcommon code, such as::
238*d47a97bdSJonathan Corbet
239*d47a97bdSJonathan Corbet	/* Make sure we're on the FooTech Vaporboard */
240*d47a97bdSJonathan Corbet	if (!mach_is_vapor())
241*d47a97bdSJonathan Corbet		return -ENODEV;
242*d47a97bdSJonathan Corbet
243*d47a97bdSJonathan Corbetalso note that the mach_is_boardname() check will be implicitly forced to
244*d47a97bdSJonathan Corbetlowercase, regardless of the fact that the mach-types entries are all
245*d47a97bdSJonathan Corbetuppercase. You can read the script if you really care, but it's pretty ugly,
246*d47a97bdSJonathan Corbetso you probably don't want to do that.
247*d47a97bdSJonathan Corbet
248*d47a97bdSJonathan CorbetNow all that's left to do is providing a defconfig for your new board. This
249*d47a97bdSJonathan Corbetway, other people who end up with this board can simply use this config
250*d47a97bdSJonathan Corbetfor reference instead of trying to guess what settings are supposed to be
251*d47a97bdSJonathan Corbetused on it.
252*d47a97bdSJonathan Corbet
253*d47a97bdSJonathan CorbetAlso, as soon as you have copied over a sample .config for your new board
254*d47a97bdSJonathan Corbet(assume arch/sh/configs/vapor_defconfig), you can also use this directly as a
255*d47a97bdSJonathan Corbetbuild target, and it will be implicitly listed as such in the help text.
256*d47a97bdSJonathan Corbet
257*d47a97bdSJonathan CorbetLooking at the 'make help' output, you should now see something like:
258*d47a97bdSJonathan Corbet
259*d47a97bdSJonathan CorbetArchitecture specific targets (sh):
260*d47a97bdSJonathan Corbet
261*d47a97bdSJonathan Corbet  =======================   =============================================
262*d47a97bdSJonathan Corbet  zImage                    Compressed kernel image (arch/sh/boot/zImage)
263*d47a97bdSJonathan Corbet  adx_defconfig             Build for adx
264*d47a97bdSJonathan Corbet  cqreek_defconfig          Build for cqreek
265*d47a97bdSJonathan Corbet  dreamcast_defconfig       Build for dreamcast
266*d47a97bdSJonathan Corbet  ...
267*d47a97bdSJonathan Corbet  vapor_defconfig           Build for vapor
268*d47a97bdSJonathan Corbet  =======================   =============================================
269*d47a97bdSJonathan Corbet
270*d47a97bdSJonathan Corbetwhich then allows you to do::
271*d47a97bdSJonathan Corbet
272*d47a97bdSJonathan Corbet    $ make ARCH=sh CROSS_COMPILE=sh4-linux- vapor_defconfig vmlinux
273*d47a97bdSJonathan Corbet
274*d47a97bdSJonathan Corbetwhich will in turn copy the defconfig for this board, run it through
275*d47a97bdSJonathan Corbetoldconfig (prompting you for any new options since the time of creation),
276*d47a97bdSJonathan Corbetand start you on your way to having a functional kernel for your new
277*d47a97bdSJonathan Corbetboard.
278