162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci#ifndef _ASM_POWERPC_MACHDEP_H
362306a36Sopenharmony_ci#define _ASM_POWERPC_MACHDEP_H
462306a36Sopenharmony_ci#ifdef __KERNEL__
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/compiler.h>
762306a36Sopenharmony_ci#include <linux/seq_file.h>
862306a36Sopenharmony_ci#include <linux/init.h>
962306a36Sopenharmony_ci#include <linux/dma-mapping.h>
1062306a36Sopenharmony_ci#include <linux/export.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cistruct pt_regs;
1362306a36Sopenharmony_cistruct pci_bus;
1462306a36Sopenharmony_cistruct device_node;
1562306a36Sopenharmony_cistruct iommu_table;
1662306a36Sopenharmony_cistruct rtc_time;
1762306a36Sopenharmony_cistruct file;
1862306a36Sopenharmony_cistruct pci_controller;
1962306a36Sopenharmony_cistruct kimage;
2062306a36Sopenharmony_cistruct pci_host_bridge;
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cistruct machdep_calls {
2362306a36Sopenharmony_ci	const char	*name;
2462306a36Sopenharmony_ci	const char	*compatible;
2562306a36Sopenharmony_ci#ifdef CONFIG_PPC64
2662306a36Sopenharmony_ci#ifdef CONFIG_PM
2762306a36Sopenharmony_ci	void		(*iommu_restore)(void);
2862306a36Sopenharmony_ci#endif
2962306a36Sopenharmony_ci#ifdef CONFIG_MEMORY_HOTPLUG
3062306a36Sopenharmony_ci	unsigned long	(*memory_block_size)(void);
3162306a36Sopenharmony_ci#endif
3262306a36Sopenharmony_ci#endif /* CONFIG_PPC64 */
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci	void		(*dma_set_mask)(struct device *dev, u64 dma_mask);
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci	int		(*probe)(void);
3762306a36Sopenharmony_ci	void		(*setup_arch)(void); /* Optional, may be NULL */
3862306a36Sopenharmony_ci	/* Optional, may be NULL. */
3962306a36Sopenharmony_ci	void		(*show_cpuinfo)(struct seq_file *m);
4062306a36Sopenharmony_ci	/* Returns the current operating frequency of "cpu" in Hz */
4162306a36Sopenharmony_ci	unsigned long  	(*get_proc_freq)(unsigned int cpu);
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci	void		(*init_IRQ)(void);
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci	/* Return an irq, or 0 to indicate there are none pending. */
4662306a36Sopenharmony_ci	unsigned int	(*get_irq)(void);
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci	/* PCI stuff */
4962306a36Sopenharmony_ci	/* Called after allocating resources */
5062306a36Sopenharmony_ci	void		(*pcibios_fixup)(void);
5162306a36Sopenharmony_ci	void		(*pci_irq_fixup)(struct pci_dev *dev);
5262306a36Sopenharmony_ci	int		(*pcibios_root_bridge_prepare)(struct pci_host_bridge
5362306a36Sopenharmony_ci				*bridge);
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	/* finds all the pci_controllers present at boot */
5662306a36Sopenharmony_ci	void 		(*discover_phbs)(void);
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	/* To setup PHBs when using automatic OF platform driver for PCI */
5962306a36Sopenharmony_ci	int		(*pci_setup_phb)(struct pci_controller *host);
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci	void __noreturn	(*restart)(char *cmd);
6262306a36Sopenharmony_ci	void __noreturn (*halt)(void);
6362306a36Sopenharmony_ci	void		(*panic)(char *str);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci	long		(*time_init)(void); /* Optional, may be NULL */
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	int		(*set_rtc_time)(struct rtc_time *);
6862306a36Sopenharmony_ci	void		(*get_rtc_time)(struct rtc_time *);
6962306a36Sopenharmony_ci	time64_t	(*get_boot_time)(void);
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	void		(*calibrate_decr)(void);
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	void		(*progress)(char *, unsigned short);
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci	/* Interface for platform error logging */
7662306a36Sopenharmony_ci	void 		(*log_error)(char *buf, unsigned int err_type, int fatal);
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci	unsigned char 	(*nvram_read_val)(int addr);
7962306a36Sopenharmony_ci	void		(*nvram_write_val)(int addr, unsigned char val);
8062306a36Sopenharmony_ci	ssize_t		(*nvram_write)(char *buf, size_t count, loff_t *index);
8162306a36Sopenharmony_ci	ssize_t		(*nvram_read)(char *buf, size_t count, loff_t *index);
8262306a36Sopenharmony_ci	ssize_t		(*nvram_size)(void);
8362306a36Sopenharmony_ci	void		(*nvram_sync)(void);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci	/* Exception handlers */
8662306a36Sopenharmony_ci	int		(*system_reset_exception)(struct pt_regs *regs);
8762306a36Sopenharmony_ci	int 		(*machine_check_exception)(struct pt_regs *regs);
8862306a36Sopenharmony_ci	int		(*handle_hmi_exception)(struct pt_regs *regs);
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci	/* Early exception handlers called in realmode */
9162306a36Sopenharmony_ci	int		(*hmi_exception_early)(struct pt_regs *regs);
9262306a36Sopenharmony_ci	long		(*machine_check_early)(struct pt_regs *regs);
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci	/* Called during machine check exception to retrive fixup address. */
9562306a36Sopenharmony_ci	bool		(*mce_check_early_recovery)(struct pt_regs *regs);
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci	void            (*machine_check_log_err)(void);
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	/* Motherboard/chipset features. This is a kind of general purpose
10062306a36Sopenharmony_ci	 * hook used to control some machine specific features (like reset
10162306a36Sopenharmony_ci	 * lines, chip power control, etc...).
10262306a36Sopenharmony_ci	 */
10362306a36Sopenharmony_ci	long	 	(*feature_call)(unsigned int feature, ...);
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	/* Get legacy PCI/IDE interrupt mapping */
10662306a36Sopenharmony_ci	int		(*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	/* Get access protection for /dev/mem */
10962306a36Sopenharmony_ci	pgprot_t	(*phys_mem_access_prot)(struct file *file,
11062306a36Sopenharmony_ci						unsigned long pfn,
11162306a36Sopenharmony_ci						unsigned long size,
11262306a36Sopenharmony_ci						pgprot_t vma_prot);
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci	/*
11562306a36Sopenharmony_ci	 * Function for waiting for work with reduced power in idle loop;
11662306a36Sopenharmony_ci	 * called with interrupts disabled.
11762306a36Sopenharmony_ci	 */
11862306a36Sopenharmony_ci	void		(*power_save)(void);
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	/* Function to enable performance monitor counters for this
12162306a36Sopenharmony_ci	   platform, called once per cpu. */
12262306a36Sopenharmony_ci	void		(*enable_pmcs)(void);
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	/* Set DABR for this platform, leave empty for default implementation */
12562306a36Sopenharmony_ci	int		(*set_dabr)(unsigned long dabr,
12662306a36Sopenharmony_ci				    unsigned long dabrx);
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	/* Set DAWR for this platform, leave empty for default implementation */
12962306a36Sopenharmony_ci	int		(*set_dawr)(int nr, unsigned long dawr,
13062306a36Sopenharmony_ci				    unsigned long dawrx);
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci#ifdef CONFIG_PPC32	/* XXX for now */
13362306a36Sopenharmony_ci	/* A general init function, called by ppc_init in init/main.c.
13462306a36Sopenharmony_ci	   May be NULL. */
13562306a36Sopenharmony_ci	void		(*init)(void);
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci	/*
13862306a36Sopenharmony_ci	 * optional PCI "hooks"
13962306a36Sopenharmony_ci	 */
14062306a36Sopenharmony_ci	/* Called at then very end of pcibios_init() */
14162306a36Sopenharmony_ci	void (*pcibios_after_init)(void);
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci#endif /* CONFIG_PPC32 */
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci	/* Called in indirect_* to avoid touching devices */
14662306a36Sopenharmony_ci	int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci	/* Called after PPC generic resource fixup to perform
14962306a36Sopenharmony_ci	   machine specific fixups */
15062306a36Sopenharmony_ci	void (*pcibios_fixup_resources)(struct pci_dev *);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	/* Called for each PCI bus in the system when it's probed */
15362306a36Sopenharmony_ci	void (*pcibios_fixup_bus)(struct pci_bus *);
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci	/* Called after scan and before resource survey */
15662306a36Sopenharmony_ci	void (*pcibios_fixup_phb)(struct pci_controller *hose);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci	/*
15962306a36Sopenharmony_ci	 * Called after device has been added to bus and
16062306a36Sopenharmony_ci	 * before sysfs has been created.
16162306a36Sopenharmony_ci	 */
16262306a36Sopenharmony_ci	void (*pcibios_bus_add_device)(struct pci_dev *pdev);
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci	resource_size_t (*pcibios_default_alignment)(void);
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci#ifdef CONFIG_PCI_IOV
16762306a36Sopenharmony_ci	void (*pcibios_fixup_sriov)(struct pci_dev *pdev);
16862306a36Sopenharmony_ci	resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno);
16962306a36Sopenharmony_ci	int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs);
17062306a36Sopenharmony_ci	int (*pcibios_sriov_disable)(struct pci_dev *pdev);
17162306a36Sopenharmony_ci#endif /* CONFIG_PCI_IOV */
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci	/* Called to shutdown machine specific hardware not already controlled
17462306a36Sopenharmony_ci	 * by other drivers.
17562306a36Sopenharmony_ci	 */
17662306a36Sopenharmony_ci	void (*machine_shutdown)(void);
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci#ifdef CONFIG_KEXEC_CORE
17962306a36Sopenharmony_ci	void (*kexec_cpu_down)(int crash_shutdown, int secondary);
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci	/* Called to perform the _real_ kexec.
18262306a36Sopenharmony_ci	 * Do NOT allocate memory or fail here. We are past the point of
18362306a36Sopenharmony_ci	 * no return.
18462306a36Sopenharmony_ci	 */
18562306a36Sopenharmony_ci	void (*machine_kexec)(struct kimage *image);
18662306a36Sopenharmony_ci#endif /* CONFIG_KEXEC_CORE */
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci#ifdef CONFIG_SUSPEND
18962306a36Sopenharmony_ci	/* These are called to disable and enable, respectively, IRQs when
19062306a36Sopenharmony_ci	 * entering a suspend state.  If NULL, then the generic versions
19162306a36Sopenharmony_ci	 * will be called.  The generic versions disable/enable the
19262306a36Sopenharmony_ci	 * decrementer along with interrupts.
19362306a36Sopenharmony_ci	 */
19462306a36Sopenharmony_ci	void (*suspend_disable_irqs)(void);
19562306a36Sopenharmony_ci	void (*suspend_enable_irqs)(void);
19662306a36Sopenharmony_ci#endif
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
19962306a36Sopenharmony_ci	ssize_t (*cpu_probe)(const char *, size_t);
20062306a36Sopenharmony_ci	ssize_t (*cpu_release)(const char *, size_t);
20162306a36Sopenharmony_ci#endif
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci	int (*get_random_seed)(unsigned long *v);
20462306a36Sopenharmony_ci};
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ciextern void e500_idle(void);
20762306a36Sopenharmony_ciextern void power4_idle(void);
20862306a36Sopenharmony_ciextern void ppc6xx_idle(void);
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci/*
21162306a36Sopenharmony_ci * ppc_md contains a copy of the machine description structure for the
21262306a36Sopenharmony_ci * current platform. machine_id contains the initial address where the
21362306a36Sopenharmony_ci * description was found during boot.
21462306a36Sopenharmony_ci */
21562306a36Sopenharmony_ciextern struct machdep_calls ppc_md;
21662306a36Sopenharmony_ciextern struct machdep_calls *machine_id;
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci#define __machine_desc __section(".machine.desc")
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci#define define_machine(name)					\
22162306a36Sopenharmony_ci	extern struct machdep_calls mach_##name;		\
22262306a36Sopenharmony_ci	EXPORT_SYMBOL(mach_##name);				\
22362306a36Sopenharmony_ci	struct machdep_calls mach_##name __machine_desc =
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_cistatic inline bool __machine_is(const struct machdep_calls *md)
22662306a36Sopenharmony_ci{
22762306a36Sopenharmony_ci	WARN_ON(!machine_id); // complain if used before probe_machine()
22862306a36Sopenharmony_ci	return machine_id == md;
22962306a36Sopenharmony_ci}
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci#define machine_is(name)                                        \
23262306a36Sopenharmony_ci	({                                                      \
23362306a36Sopenharmony_ci		extern struct machdep_calls mach_##name __weak; \
23462306a36Sopenharmony_ci		__machine_is(&mach_##name);                     \
23562306a36Sopenharmony_ci	})
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_cistatic inline void log_error(char *buf, unsigned int err_type, int fatal)
23862306a36Sopenharmony_ci{
23962306a36Sopenharmony_ci	if (ppc_md.log_error)
24062306a36Sopenharmony_ci		ppc_md.log_error(buf, err_type, fatal);
24162306a36Sopenharmony_ci}
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci#define __define_machine_initcall(mach, fn, id) \
24462306a36Sopenharmony_ci	static int __init __machine_initcall_##mach##_##fn(void) { \
24562306a36Sopenharmony_ci		if (machine_is(mach)) return fn(); \
24662306a36Sopenharmony_ci		return 0; \
24762306a36Sopenharmony_ci	} \
24862306a36Sopenharmony_ci	__define_initcall(__machine_initcall_##mach##_##fn, id);
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ci#define machine_early_initcall(mach, fn)	__define_machine_initcall(mach, fn, early)
25162306a36Sopenharmony_ci#define machine_core_initcall(mach, fn)		__define_machine_initcall(mach, fn, 1)
25262306a36Sopenharmony_ci#define machine_core_initcall_sync(mach, fn)	__define_machine_initcall(mach, fn, 1s)
25362306a36Sopenharmony_ci#define machine_postcore_initcall(mach, fn)	__define_machine_initcall(mach, fn, 2)
25462306a36Sopenharmony_ci#define machine_postcore_initcall_sync(mach, fn)	__define_machine_initcall(mach, fn, 2s)
25562306a36Sopenharmony_ci#define machine_arch_initcall(mach, fn)		__define_machine_initcall(mach, fn, 3)
25662306a36Sopenharmony_ci#define machine_arch_initcall_sync(mach, fn)	__define_machine_initcall(mach, fn, 3s)
25762306a36Sopenharmony_ci#define machine_subsys_initcall(mach, fn)	__define_machine_initcall(mach, fn, 4)
25862306a36Sopenharmony_ci#define machine_subsys_initcall_sync(mach, fn)	__define_machine_initcall(mach, fn, 4s)
25962306a36Sopenharmony_ci#define machine_fs_initcall(mach, fn)		__define_machine_initcall(mach, fn, 5)
26062306a36Sopenharmony_ci#define machine_fs_initcall_sync(mach, fn)	__define_machine_initcall(mach, fn, 5s)
26162306a36Sopenharmony_ci#define machine_rootfs_initcall(mach, fn)	__define_machine_initcall(mach, fn, rootfs)
26262306a36Sopenharmony_ci#define machine_device_initcall(mach, fn)	__define_machine_initcall(mach, fn, 6)
26362306a36Sopenharmony_ci#define machine_device_initcall_sync(mach, fn)	__define_machine_initcall(mach, fn, 6s)
26462306a36Sopenharmony_ci#define machine_late_initcall(mach, fn)		__define_machine_initcall(mach, fn, 7)
26562306a36Sopenharmony_ci#define machine_late_initcall_sync(mach, fn)	__define_machine_initcall(mach, fn, 7s)
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci#endif /* __KERNEL__ */
26862306a36Sopenharmony_ci#endif /* _ASM_POWERPC_MACHDEP_H */
269