linux/arch/powerpc/include/asm/machdep.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-or-later */
   2#ifndef _ASM_POWERPC_MACHDEP_H
   3#define _ASM_POWERPC_MACHDEP_H
   4#ifdef __KERNEL__
   5
   6#include <linux/seq_file.h>
   7#include <linux/init.h>
   8#include <linux/dma-mapping.h>
   9#include <linux/export.h>
  10
  11#include <asm/setup.h>
  12
  13/* We export this macro for external modules like Alsa to know if
  14 * ppc_md.feature_call is implemented or not
  15 */
  16#define CONFIG_PPC_HAS_FEATURE_CALLS
  17
  18struct pt_regs;
  19struct pci_bus; 
  20struct device_node;
  21struct iommu_table;
  22struct rtc_time;
  23struct file;
  24struct pci_controller;
  25struct kimage;
  26struct pci_host_bridge;
  27
  28struct machdep_calls {
  29        char            *name;
  30#ifdef CONFIG_PPC64
  31#ifdef CONFIG_PM
  32        void            (*iommu_restore)(void);
  33#endif
  34#ifdef CONFIG_MEMORY_HOTPLUG
  35        unsigned long   (*memory_block_size)(void);
  36#endif
  37#endif /* CONFIG_PPC64 */
  38
  39        void            (*dma_set_mask)(struct device *dev, u64 dma_mask);
  40
  41        int             (*probe)(void);
  42        void            (*setup_arch)(void); /* Optional, may be NULL */
  43        /* Optional, may be NULL. */
  44        void            (*show_cpuinfo)(struct seq_file *m);
  45        /* Returns the current operating frequency of "cpu" in Hz */
  46        unsigned long   (*get_proc_freq)(unsigned int cpu);
  47
  48        void            (*init_IRQ)(void);
  49
  50        /* Return an irq, or 0 to indicate there are none pending. */
  51        unsigned int    (*get_irq)(void);
  52
  53        /* PCI stuff */
  54        /* Called after allocating resources */
  55        void            (*pcibios_fixup)(void);
  56        void            (*pci_irq_fixup)(struct pci_dev *dev);
  57        int             (*pcibios_root_bridge_prepare)(struct pci_host_bridge
  58                                *bridge);
  59
  60        /* finds all the pci_controllers present at boot */
  61        void            (*discover_phbs)(void);
  62
  63        /* To setup PHBs when using automatic OF platform driver for PCI */
  64        int             (*pci_setup_phb)(struct pci_controller *host);
  65
  66        void __noreturn (*restart)(char *cmd);
  67        void __noreturn (*halt)(void);
  68        void            (*panic)(char *str);
  69
  70        long            (*time_init)(void); /* Optional, may be NULL */
  71
  72        int             (*set_rtc_time)(struct rtc_time *);
  73        void            (*get_rtc_time)(struct rtc_time *);
  74        time64_t        (*get_boot_time)(void);
  75
  76        void            (*calibrate_decr)(void);
  77
  78        void            (*progress)(char *, unsigned short);
  79
  80        /* Interface for platform error logging */
  81        void            (*log_error)(char *buf, unsigned int err_type, int fatal);
  82
  83        unsigned char   (*nvram_read_val)(int addr);
  84        void            (*nvram_write_val)(int addr, unsigned char val);
  85        ssize_t         (*nvram_write)(char *buf, size_t count, loff_t *index);
  86        ssize_t         (*nvram_read)(char *buf, size_t count, loff_t *index);  
  87        ssize_t         (*nvram_size)(void);            
  88        void            (*nvram_sync)(void);
  89
  90        /* Exception handlers */
  91        int             (*system_reset_exception)(struct pt_regs *regs);
  92        int             (*machine_check_exception)(struct pt_regs *regs);
  93        int             (*handle_hmi_exception)(struct pt_regs *regs);
  94
  95        /* Early exception handlers called in realmode */
  96        int             (*hmi_exception_early)(struct pt_regs *regs);
  97        long            (*machine_check_early)(struct pt_regs *regs);
  98
  99        /* Called during machine check exception to retrive fixup address. */
 100        bool            (*mce_check_early_recovery)(struct pt_regs *regs);
 101
 102        /* Motherboard/chipset features. This is a kind of general purpose
 103         * hook used to control some machine specific features (like reset
 104         * lines, chip power control, etc...).
 105         */
 106        long            (*feature_call)(unsigned int feature, ...);
 107
 108        /* Get legacy PCI/IDE interrupt mapping */ 
 109        int             (*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
 110        
 111        /* Get access protection for /dev/mem */
 112        pgprot_t        (*phys_mem_access_prot)(struct file *file,
 113                                                unsigned long pfn,
 114                                                unsigned long size,
 115                                                pgprot_t vma_prot);
 116
 117        /*
 118         * Function for waiting for work with reduced power in idle loop;
 119         * called with interrupts disabled.
 120         */
 121        void            (*power_save)(void);
 122
 123        /* Function to enable performance monitor counters for this
 124           platform, called once per cpu. */
 125        void            (*enable_pmcs)(void);
 126
 127        /* Set DABR for this platform, leave empty for default implementation */
 128        int             (*set_dabr)(unsigned long dabr,
 129                                    unsigned long dabrx);
 130
 131        /* Set DAWR for this platform, leave empty for default implementation */
 132        int             (*set_dawr)(int nr, unsigned long dawr,
 133                                    unsigned long dawrx);
 134
 135#ifdef CONFIG_PPC32     /* XXX for now */
 136        /* A general init function, called by ppc_init in init/main.c.
 137           May be NULL. */
 138        void            (*init)(void);
 139
 140        /*
 141         * optional PCI "hooks"
 142         */
 143        /* Called at then very end of pcibios_init() */
 144        void (*pcibios_after_init)(void);
 145
 146#endif /* CONFIG_PPC32 */
 147
 148        /* Called in indirect_* to avoid touching devices */
 149        int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
 150
 151        /* Called after PPC generic resource fixup to perform
 152           machine specific fixups */
 153        void (*pcibios_fixup_resources)(struct pci_dev *);
 154
 155        /* Called for each PCI bus in the system when it's probed */
 156        void (*pcibios_fixup_bus)(struct pci_bus *);
 157
 158        /* Called after scan and before resource survey */
 159        void (*pcibios_fixup_phb)(struct pci_controller *hose);
 160
 161        /*
 162         * Called after device has been added to bus and
 163         * before sysfs has been created.
 164         */
 165        void (*pcibios_bus_add_device)(struct pci_dev *pdev);
 166
 167        resource_size_t (*pcibios_default_alignment)(void);
 168
 169#ifdef CONFIG_PCI_IOV
 170        void (*pcibios_fixup_sriov)(struct pci_dev *pdev);
 171        resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno);
 172        int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs);
 173        int (*pcibios_sriov_disable)(struct pci_dev *pdev);
 174#endif /* CONFIG_PCI_IOV */
 175
 176        /* Called to shutdown machine specific hardware not already controlled
 177         * by other drivers.
 178         */
 179        void (*machine_shutdown)(void);
 180
 181#ifdef CONFIG_KEXEC_CORE
 182        void (*kexec_cpu_down)(int crash_shutdown, int secondary);
 183
 184        /* Called to perform the _real_ kexec.
 185         * Do NOT allocate memory or fail here. We are past the point of
 186         * no return.
 187         */
 188        void (*machine_kexec)(struct kimage *image);
 189#endif /* CONFIG_KEXEC_CORE */
 190
 191#ifdef CONFIG_SUSPEND
 192        /* These are called to disable and enable, respectively, IRQs when
 193         * entering a suspend state.  If NULL, then the generic versions
 194         * will be called.  The generic versions disable/enable the
 195         * decrementer along with interrupts.
 196         */
 197        void (*suspend_disable_irqs)(void);
 198        void (*suspend_enable_irqs)(void);
 199#endif
 200
 201#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
 202        ssize_t (*cpu_probe)(const char *, size_t);
 203        ssize_t (*cpu_release)(const char *, size_t);
 204#endif
 205
 206#ifdef CONFIG_ARCH_RANDOM
 207        int (*get_random_seed)(unsigned long *v);
 208#endif
 209};
 210
 211extern void e500_idle(void);
 212extern void power4_idle(void);
 213extern void ppc6xx_idle(void);
 214extern void book3e_idle(void);
 215
 216/*
 217 * ppc_md contains a copy of the machine description structure for the
 218 * current platform. machine_id contains the initial address where the
 219 * description was found during boot.
 220 */
 221extern struct machdep_calls ppc_md;
 222extern struct machdep_calls *machine_id;
 223
 224#define __machine_desc __section(".machine.desc")
 225
 226#define define_machine(name)                                    \
 227        extern struct machdep_calls mach_##name;                \
 228        EXPORT_SYMBOL(mach_##name);                             \
 229        struct machdep_calls mach_##name __machine_desc =
 230
 231#define machine_is(name) \
 232        ({ \
 233                extern struct machdep_calls mach_##name \
 234                        __attribute__((weak));           \
 235                machine_id == &mach_##name; \
 236        })
 237
 238extern void probe_machine(void);
 239
 240#ifdef CONFIG_PPC_PMAC
 241/*
 242 * Power macintoshes have either a CUDA, PMU or SMU controlling
 243 * system reset, power, NVRAM, RTC.
 244 */
 245typedef enum sys_ctrler_kind {
 246        SYS_CTRLER_UNKNOWN = 0,
 247        SYS_CTRLER_CUDA = 1,
 248        SYS_CTRLER_PMU = 2,
 249        SYS_CTRLER_SMU = 3,
 250} sys_ctrler_t;
 251extern sys_ctrler_t sys_ctrler;
 252
 253#endif /* CONFIG_PPC_PMAC */
 254
 255static inline void log_error(char *buf, unsigned int err_type, int fatal)
 256{
 257        if (ppc_md.log_error)
 258                ppc_md.log_error(buf, err_type, fatal);
 259}
 260
 261#define __define_machine_initcall(mach, fn, id) \
 262        static int __init __machine_initcall_##mach##_##fn(void) { \
 263                if (machine_is(mach)) return fn(); \
 264                return 0; \
 265        } \
 266        __define_initcall(__machine_initcall_##mach##_##fn, id);
 267
 268#define machine_early_initcall(mach, fn)        __define_machine_initcall(mach, fn, early)
 269#define machine_core_initcall(mach, fn)         __define_machine_initcall(mach, fn, 1)
 270#define machine_core_initcall_sync(mach, fn)    __define_machine_initcall(mach, fn, 1s)
 271#define machine_postcore_initcall(mach, fn)     __define_machine_initcall(mach, fn, 2)
 272#define machine_postcore_initcall_sync(mach, fn)        __define_machine_initcall(mach, fn, 2s)
 273#define machine_arch_initcall(mach, fn)         __define_machine_initcall(mach, fn, 3)
 274#define machine_arch_initcall_sync(mach, fn)    __define_machine_initcall(mach, fn, 3s)
 275#define machine_subsys_initcall(mach, fn)       __define_machine_initcall(mach, fn, 4)
 276#define machine_subsys_initcall_sync(mach, fn)  __define_machine_initcall(mach, fn, 4s)
 277#define machine_fs_initcall(mach, fn)           __define_machine_initcall(mach, fn, 5)
 278#define machine_fs_initcall_sync(mach, fn)      __define_machine_initcall(mach, fn, 5s)
 279#define machine_rootfs_initcall(mach, fn)       __define_machine_initcall(mach, fn, rootfs)
 280#define machine_device_initcall(mach, fn)       __define_machine_initcall(mach, fn, 6)
 281#define machine_device_initcall_sync(mach, fn)  __define_machine_initcall(mach, fn, 6s)
 282#define machine_late_initcall(mach, fn)         __define_machine_initcall(mach, fn, 7)
 283#define machine_late_initcall_sync(mach, fn)    __define_machine_initcall(mach, fn, 7s)
 284
 285#endif /* __KERNEL__ */
 286#endif /* _ASM_POWERPC_MACHDEP_H */
 287