From patchwork Tue Mar 29 14:08:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 826 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:46:11 -0000 Delivered-To: patches@linaro.org Received: by 10.42.161.68 with SMTP id s4cs190867icx; Tue, 29 Mar 2011 07:08:31 -0700 (PDT) Received: by 10.14.50.197 with SMTP id z45mr2335341eeb.248.1301407710554; Tue, 29 Mar 2011 07:08:30 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk [81.2.115.146]) by mx.google.com with ESMTPS id r15si8683111wec.102.2011.03.29.07.08.27 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 29 Mar 2011 07:08:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1Q4Zar-0006OS-2p; Tue, 29 Mar 2011 15:08:25 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Blue Swirl Subject: [PATCH v3 6/7] hw/sun4m: Use a macro to hide the repetitive board init functions Date: Tue, 29 Mar 2011 15:08:23 +0100 Message-Id: <1301407704-24541-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1301407704-24541-1-git-send-email-peter.maydell@linaro.org> References: <1301407704-24541-1-git-send-email-peter.maydell@linaro.org> Tidy up the repetitive board init functions (which are all the same apart from which hwdef struct they pass in). This also lets us add an assertion that the hwdef points to the init function which uses that hwdef, rather than some other one. Signed-off-by: Peter Maydell --- hw/sun4m.c | 138 ++++++++++-------------------------------------------------- 1 files changed, 22 insertions(+), 116 deletions(-) diff --git a/hw/sun4m.c b/hw/sun4m.c index 2ae8c45..f130fc9 100644 --- a/hw/sun4m.c +++ b/hw/sun4m.c @@ -1001,96 +1001,27 @@ enum { static const struct sun4m_hwdef sun4m_hwdefs[]; -/* SPARCstation 5 hardware initialisation */ -static void ss5_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} - -/* SPARCstation 10 hardware initialisation */ -static void ss10_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} - -/* SPARCserver 600MP hardware initialisation */ -static void ss600mp_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, - const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} - -/* SPARCstation 20 hardware initialisation */ -static void ss20_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} - -/* SPARCstation Voyager hardware initialisation */ -static void vger_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); +#define SUN4_INITFN(NAME, SUBARCH, OFFSET) \ +static void NAME##_init(ram_addr_t RAM_size, \ + const char *boot_device, \ + const char *kernel_filename, const char *kernel_cmdline, \ + const char *initrd_filename, const char *cpu_model) \ +{ \ + assert(SUBARCH##_hwdefs[OFFSET].machine.init == NAME##_init); \ + SUBARCH##_hw_init(&SUBARCH##_hwdefs[OFFSET], RAM_size, boot_device, \ + kernel_filename, kernel_cmdline, initrd_filename, \ + cpu_model); \ } -/* SPARCstation LX hardware initialisation */ -static void ss_lx_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} - -/* SPARCstation 4 hardware initialisation */ -static void ss4_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} - -/* SPARCClassic hardware initialisation */ -static void scls_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} - -/* SPARCbook hardware initialisation */ -static void sbook_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} +SUN4_INITFN(ss5, sun4m, 0) +SUN4_INITFN(ss10, sun4m, 1) +SUN4_INITFN(ss600mp, sun4m, 2) +SUN4_INITFN(ss20, sun4m, 3) +SUN4_INITFN(vger, sun4m, 4) +SUN4_INITFN(ss_lx, sun4m, 5) +SUN4_INITFN(ss4, sun4m, 6) +SUN4_INITFN(scls, sun4m, 7) +SUN4_INITFN(sbook, sun4m, 8) static const struct sun4m_hwdef sun4m_hwdefs[] = { /* SS-5 */ @@ -1532,25 +1463,8 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size, static const struct sun4d_hwdef sun4d_hwdefs[]; -/* SPARCserver 1000 hardware initialisation */ -static void ss1000_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} - -/* SPARCcenter 2000 hardware initialisation */ -static void ss2000_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} +SUN4_INITFN(ss1000, sun4d, 0) +SUN4_INITFN(ss2000, sun4d, 1) static const struct sun4d_hwdef sun4d_hwdefs[] = { /* SS-1000 */ @@ -1756,15 +1670,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size, static const struct sun4c_hwdef sun4c_hwdefs[]; -/* SPARCstation 2 hardware initialisation */ -static void ss2_init(ram_addr_t RAM_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename, - kernel_cmdline, initrd_filename, cpu_model); -} +SUN4_INITFN(ss2, sun4c, 0) static const struct sun4c_hwdef sun4c_hwdefs[] = { /* SS-2 */