Commit f3e79aa9 authored by Mao Minkai's avatar Mao Minkai Committed by guzitao
Browse files

sw64: add boot and setup routines

Sunway inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8Y8CY



--------------------------------

Add basic boot, setup and reset routines for SW64.

Signed-off-by: default avatarMao Minkai <maominkai@wxiat.com>
Reviewed-by: default avatarHe Sheng <hesheng@wxiat.com>
Signed-off-by: default avatarGu Zitao <guzitao@wxiat.com>
parent 74e154e0
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_SW64_PLATFORM_H
#define _ASM_SW64_PLATFORM_H

#include <linux/types.h>
#if defined(CONFIG_UNCORE_XUELANG)
#include <asm/uncore_io_xuelang.h>
#elif defined(CONFIG_UNCORE_JUNZHANG)
#include <asm/uncore_io_junzhang.h>
#endif

#ifdef CONFIG_EFI
#define BIOS_VERSION_GUID       EFI_GUID(0xc47a23c3, 0xcebb, 0x4cc9, 0xa5, 0xe2, 0xde, 0xd0, 0x8f, 0xe4, 0x20, 0xb5)

#define BIOS_SUPPORT_RESET_CLALLBACK(bios_version) ((bios_version) != NULL)

extern unsigned long bios_version;

#endif

extern struct boot_params *sunway_boot_params;

extern void sw64_halt(void);
extern void sw64_poweroff(void);
extern void sw64_restart(void);
extern void (*pm_restart)(void);
extern void (*pm_halt)(void);
extern int i2c_set_adapter(void);
extern void cpld_write(uint8_t slave_addr, uint8_t reg, uint8_t data);
extern void fix_jm585_reset(void);

#endif /* _ASM_SW64_PLATFORM_H */
+51 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_SW64_SETUP_H
#define _ASM_SW64_SETUP_H

#include <uapi/asm/setup.h>

/*
 * We leave one page for the initial stack page, and one page for
 * the initial process structure. Also, the console eats 3 MB for
 * the initial bootloader (one of which we can reclaim later).
 */
#define BOOT_PCB		0x20000000
#define BOOT_ADDR		0x20000000
/* Remove when official MILO sources have ELF support: */
#define BOOT_SIZE		(16 * 1024)

#define KERNEL_START_PHYS	CONFIG_PHYSICAL_START
#define KERNEL_START		(__START_KERNEL_map + CONFIG_PHYSICAL_START)

/* INIT_STACK may be used for merging lwk to kernel*/
#define INIT_STACK		(KERNEL_START + 0x02000)

/*
 * This is setup by the secondary bootstrap loader.  Because
 * the zero page is zeroed out as soon as the vm system is
 * initialized, we need to copy things out into a more permanent
 * place.
 */
#define PARAM			(KERNEL_START + 0x0A000)
#define COMMAND_LINE		((char *)(KERNEL_START + 0x0B000))
#define INITRD_START		(*(unsigned long *)(PARAM + 0x100))
#define INITRD_SIZE		(*(unsigned long *)(PARAM + 0x108))
#define DTB_START		(*(unsigned long *)(PARAM + 0x118))

#define _TEXT_START		(KERNEL_START + 0x10000)

#define COMMAND_LINE_OFF	(0x10000UL - 0xB000UL)
#define INITRD_START_OFF	(0x10000UL - 0xA100UL)
#define INITRD_SIZE_OFF		(0x10000UL - 0xA108UL)

/* Motherboard Configuration Tables */
#define MB_CONFIG_START		0x908000
#define MB_MCLK			(MB_CONFIG_START + 0x1)
#define MB_EXTCLK		(MB_CONFIG_START + 0x11)

#ifndef __ASSEMBLY__
#include <asm/bootparam.h>
extern struct boot_params *sunway_boot_params;
#endif

#endif /* _ASM_SW64_SETUP_H */
+50 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_SW64_SW64_INIT_H
#define _ASM_SW64_SW64_INIT_H

#include <linux/cpu.h>
#include <linux/pci.h>

#include <asm/sw64io.h>

struct sw64_early_init_ops {
	void (*setup_core_map)(struct cpumask *cpumask);
	unsigned long (*get_node_mem)(int nodeid);
	void (*get_smp_info)(void);
};

struct sw64_pci_init_ops {
	int (*map_irq)(const struct pci_dev *dev, u8 slot, u8 pin);
	unsigned long (*get_rc_enable)(unsigned long node);
	void (*hose_init)(struct pci_controller *hose);
	void (*set_rc_piu)(unsigned long node, unsigned long index);
	int (*check_pci_linkup)(unsigned long node, unsigned long index);
	void (*set_intx)(unsigned long node, unsigned long index,
			unsigned long int_conf);
};


struct sw64_chip_init_ops {
	struct sw64_early_init_ops	early_init;
	struct sw64_pci_init_ops	pci_init;
	void (*fixup)(void);
};

struct sw64_chip_ops {
	int (*get_cpu_num)(void);
	void (*device_interrupt)(unsigned long irq_info);
	void (*suspend)(bool wake);
	void (*fixup)(void);
};

extern void sw64_init_noop(void);
extern void setup_chip_ops(void);
extern struct sw64_chip_ops *sw64_chip;
extern struct sw64_chip_init_ops *sw64_chip_init;
#ifdef CONFIG_PM
extern struct syscore_ops io_syscore_ops;
#endif

DECLARE_PER_CPU(unsigned long, hard_node_id);

#endif /* _ASM_SW64_SW64_INIT_H */
+22 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _UAPI_ASM_SW64_BOOTPARAM_H
#define _UAPI_ASM_SW64_BOOTPARAM_H

#ifndef __ASSEMBLY__

#include <linux/types.h>

struct boot_params {
	__u64 initrd_start;			/* logical address of initrd */
	__u64 initrd_size;			/* size of initrd */
	__u64 dtb_start;			/* logical address of dtb */
	__u64 efi_systab;			/* logical address of EFI system table */
	__u64 efi_memmap;			/* logical address of EFI memory map */
	__u64 efi_memmap_size;			/* size of EFI memory map */
	__u64 efi_memdesc_size;			/* size of an EFI memory map descriptor */
	__u64 efi_memdesc_version;		/* memory descriptor version */
	__u64 cmdline;				/* logical address of cmdline */
};
#endif

#endif /* _UAPI_ASM_SW64_BOOTPARAM_H */
+99 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * SW64 cacheinfo support
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 * kind, whether express or implied; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <linux/cacheinfo.h>

#include <asm/topology.h>

/* Populates leaf and increments to next leaf */
#define populate_cache(cache, leaf, c_level, c_type, c_id)	\
do {								\
	leaf->id = c_id;					\
	leaf->attributes = CACHE_ID;				\
	leaf->type = c_type;					\
	leaf->level = c_level;					\
	leaf->coherency_line_size = c->cache.linesz;		\
	leaf->number_of_sets = c->cache.sets;			\
	leaf->ways_of_associativity = c->cache.ways;		\
	leaf->size = c->cache.size;				\
	leaf++;							\
} while (0)

int init_cache_level(unsigned int cpu)
{
	struct cpuinfo_sw64 *c = &cpu_data[cpu];
	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
	int levels = 0, leaves = 0;

	/*
	 * If Dcache is not set, we assume the cache structures
	 * are not properly initialized.
	 */
	if (c->dcache.size)
		levels += 1;
	else
		return -ENOENT;


	leaves += (c->icache.size) ? 2 : 1;

	if (c->scache.size) {
		levels++;
		leaves++;
	}

	if (c->tcache.size) {
		levels++;
		leaves++;
	}

	this_cpu_ci->num_levels = levels;
	this_cpu_ci->num_leaves = leaves;
	return 0;
}

int populate_cache_leaves(unsigned int cpu)
{
	struct cpuinfo_sw64 *c = &cpu_data[cpu];
	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
	struct cacheinfo *this_leaf = this_cpu_ci->info_list;
	struct cpu_topology *topo = &cpu_topology[cpu];

	if (c->icache.size) {
		cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map);
		populate_cache(dcache, this_leaf, 1, CACHE_TYPE_DATA, cpu);
		cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map);
		populate_cache(icache, this_leaf, 1, CACHE_TYPE_INST, cpu);

	} else {
		cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map);
		populate_cache(dcache, this_leaf, 1, CACHE_TYPE_UNIFIED, cpu);
	}

	if (c->scache.size) {
		cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map);
		populate_cache(scache, this_leaf, 2, CACHE_TYPE_UNIFIED, cpu);
	}

	if (c->tcache.size) {
		cpumask_copy(&this_leaf->shared_cpu_map, topology_llc_cpumask(cpu));
		populate_cache(tcache, this_leaf, 3, CACHE_TYPE_UNIFIED, topo->package_id);
	}

	this_cpu_ci->cpu_map_populated = true;

	return 0;
}
Loading