cpr.h revision e7cbe64f7a72dae5cb44f100db60ca88f3313c65
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_CPR_H
#define _SYS_CPR_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/compress.h>
#include <sys/archsystm.h>
/*
* definitions for kernel, cprboot, pmconfig
*/
#define CPR_VERSION 6
#define CPR_CONFIG "/etc/.cpr_config"
/*
* magic numbers for cpr files
*/
/*
* max(strlen("true"), strlen("false")) + 1
*/
#define PROP_BOOL_LEN 6
#define PROP_MOD 'Y'
#define PROP_NOMOD 'N'
/*
* max property name length used
* max property count
*/
#define CPR_MAXPLEN 15
#define CPR_MAXPROP 5
/*
*/
struct cpr_prop_info {
char mod;
char name[CPR_MAXPLEN];
char value[OBP_MAXPATHLEN];
};
typedef struct cpr_prop_info cprop_t;
struct cpr_default_mini {
int magic; /* magic word for booter */
int reusable; /* true if resuable statefile */
};
typedef struct cpr_default_mini cmini_t;
struct cpr_default_info {
};
typedef struct cpr_default_info cdef_t;
/*
* Configuration info provided by user via pmconfig.
*
* The first part (cf_type, cf_path, cf_fs, cf_devfs, cf_dev_prom)
* is used by both the cpr kernel module and cpr booter program
* to locate the statefile.
*
* cf_type CFT_UFS
* cf_path (path within file system) ".CPR"
* cf_dev_prom (prom device path of the above disk partition)
*
* the fields would have the typical values shown below:
*
* cf_type CFT_SPEC
* cf_path ignored
* cf_fs ignored
* cf_dev_prom (prom device path of the above special file)
*
* If the statefile is on a zvol, the fields would have these values:
*
* cf_type CFT_ZVOL
* cf_path ignored
* cf_dev_prom (prom device path of the above special file)
*
* The rest of the fields are autoshutdown and autopm configuration related.
* They are updated by pmconfig and consumed by both powerd and dtpower.
*/
struct cprconfig {
int cf_magic; /* magic word for */
/* booter to verify */
int cf_type; /* CFT_UFS or CFT_SPEC */
/* for the state file */
/* holding state file */
/* for above mount pt. */
/* above filesystem */
/*
* autoshutdown configuration fields
*/
int is_cpr_capable; /* 0 - False, 1 - True */
int is_cpr_default; /* 0 - False, 1 - True */
int is_autowakeup_capable; /* 0 - False, 1 - True */
int as_idle; /* idle time in min */
int as_sh; /* Start_time hour */
int as_sm; /* Start_time minutes */
int as_fh; /* Finish_time hour */
int as_fm; /* Finish_time minute */
/* "shutdown", "autowakeup" */
/* or "noshutdown" */
int ttychars_thold; /* default = 0 */
float loadaverage_thold; /* default = 0.04 */
int diskreads_thold; /* default = 0 */
int nfsreqs_thold; /* default = 0 */
/*
* autopm behavior field
*/
int is_autopm_default; /* 0 - False, 1 - True */
/* "default" */
};
/*
* values for cf_type
*/
/*
* definitions for kernel, cprboot
*/
#ifdef _KERNEL
#include <sys/sysmacros.h>
#include <sys/cpr_impl.h>
extern int cpr_debug;
#define errp prom_printf
#define DPRINT
/*
* CPR_DEBUG1 displays the main flow of CPR. Use it to identify which
* sub-module of CPR causes problems.
* CPR_DEBUG2 displays minor stuff that normally won't matter.
* CPR_DEBUG3 displays some big loops (cpr_dump); requires much longer runtime.
* CPR_DEBUG4 displays lots of cprboot output, cpr_read and page handling.
* CPR_DEBUG5 various, mostly unique stuff
* CPR_DEBUG9 displays statistical data for CPR on console (by using printf),
* such as num page invalidated, etc.
*/
#define CPR_DEBUG1 0x1
#define CPR_DEBUG2 0x2
#define CPR_DEBUG3 0x4
#define CPR_DEBUG4 0x8
#define CPR_DEBUG5 0x10
#define CPR_DEBUG6 0x20
#define CPR_DEBUG7 0x40
#define CPR_DEBUG8 0x80
#define CPR_DEBUG9 CPR_DEBUG6
#define DBG_DONTSHOWRANGE 0
#define DBG_SHOWRANGE 1
/*
* CPR FILE FORMAT:
*
* Dump Header: general dump data:
* cpr_dump_desc
*
* Machdep descriptor: cpr_machdep_desc
* cpr_sun4m_machdep
* cpr_sun4u_machdep, var length prom words
*
* Page Map: bitmap record consisting of a descriptor and data:
* cpr_bitmap_desc
* (char) bitmap[cpr_bitmap_desc.cbd_size]
*
* Page data: Contains one or more physical page records,
* each record consists of a descriptor and data:
* cpr_page_desc
* (char) page_data[cpr_page_desc.cpd_offset]
*
* Terminator: end marker
* cpr_terminator
*
* NOTE: cprboot now supports both ILP32 and LP64 kernels;
* the size of these structures written to a cpr statefile
* must be the same for ILP32 and LP64. For details, see
*/
/*
* header at the begining of the dump data section
*/
struct cpr_dump_desc {
int cdd_bitmaprec; /* number of bitmap records */
int cdd_dumppgsize; /* total # of frames dumped, in pages */
int cdd_test_mode; /* true if called by uadmin test mode */
int cdd_debug; /* turn on debug in cprboot */
};
typedef struct cpr_dump_desc cdd_t;
/*
* physical memory bitmap descriptor, preceeds the actual bitmap.
*/
struct cpr_bitmap_desc {
};
typedef struct cpr_bitmap_desc cbd_t;
/*
* Maximum supported bitmap descriptors; 1-2 + null-terminator is common
*/
/*
* Describes the contiguous pages saved in the storage area.
* To save space data will be compressed before saved.
* However some data end up bigger after compression.
* In that case, we save the raw data and make a note
* of it in the csd_clean_compress field.
*/
struct cpr_storage_desc {
int csd_clean_compressed;
#ifdef DEBUG
#endif
};
typedef struct cpr_storage_desc csd_t;
/*
* Describes saved pages, preceeds page data;
* cpd_lenth len is important when pages are compressed.
*/
struct cpr_page_desc {
};
typedef struct cpr_page_desc cpd_t;
/*
* cpd_flag values
*/
/*
* machdep header stores the length of the platform specific information
* that are used by resume.
*
* Note: the md_size field is the total length of the machine dependent
* information. This always includes a fixed length section and may
* include a variable length section following it on some platforms.
*/
struct cpr_machdep_desc {
};
typedef struct cpr_machdep_desc cmd_t;
typedef struct timespec32 cpr_time_t;
struct cpr_terminator {
};
typedef struct cpr_terminator ctrm_t;
#define REGULAR_BITMAP 1
#define VOLATILE_BITMAP 0
/*
* reference the right bitmap based on the arg descriptor and flag
*/
/*
* checks if a phys page is within the range covered by a bitmap
*/
#define WRITE_TO_STATEFILE 0
#define SAVE_TO_STORAGE 1
#define STORAGE_DESC_ALLOC 2
/*
* prom_read() max is 32k
* for sun4m, page size is 4k, CPR_MAXCONTIG is 8
* for sun4u, page size is 8k, CPR_MAXCONTIG is 4
*/
#define PROM_MAX_READ 0x8000
#define CPR_MAX_BLOCK 0x8000
/*
* converts byte size to bitmap size; 1 bit represents one phys page
*/
/*
* redefinitions of uadmin subcommands for A_FREEZE
*/
#define AD_CPR_DEBUG8 108
/*
* Suspend to RAM test points.
* Probably belong above, but are placed here for now.
*/
/* S3 leave hardware on and return success */
#define AD_LOOPBACK_SUSPEND_TO_RAM_PASS 22
/* S3 leave hardware on and return failure */
#define AD_LOOPBACK_SUSPEND_TO_RAM_FAIL 23
/* S3 ignored devices that fail to suspend */
#define AD_FORCE_SUSPEND_TO_RAM 24
/* S3 on a specified device */
#define AD_DEVICE_SUSPEND_TO_RAM 25
/*
* Temporary definition of the Suspend to RAM development subcommands
* so that non-ON apps will work after initial integration.
*/
#define DEV_SUSPEND_TO_RAM 200
#define DEV_CHECK_SUSPEND_TO_RAM 201
/*
* cprboot related information and definitions.
* The statefile names are hardcoded for now.
*/
#define CPR_DEFAULT "/.cpr_default"
#define CPR_STATE_FILE "/.CPR"
/*
* definitions for CPR statistics
*/
#define CPR_E_NAMELEN 64
#define CPR_E_MAX_EVENTNUM 64
struct cpr_tdata {
};
struct cpr_event {
long ce_ntests; /* num of the events since loaded */
char ce_name[CPR_E_NAMELEN];
};
struct cpr_stat {
int cs_ntests; /* num of cpr's since loaded */
int cs_mclustsz; /* average cluster size: all in bytes */
int cs_upage2statef; /* actual # of upages gone to statef */
int cs_min_comprate; /* minimum compression ratio * 100 */
};
/*
* macros for CPR statistics evaluation
*/
#define CPR_STAT_EVENT_START(s) cpr_stat_event_start(s, 0)
#define CPR_STAT_EVENT_END(s) cpr_stat_event_end(s, 0)
/*
* use the following is other time zone is required
*/
#define CPR_STAT_EVENT_START_TMZ(s, t) cpr_stat_event_start(s, t)
#define CPR_STAT_EVENT_END_TMZ(s, t) cpr_stat_event_end(s, t)
/*
* State Structure for CPR
*/
typedef struct cpr {
int c_substate; /* tracking suspend progress */
int c_fcn; /* uadmin subcommand */
char c_alloc_cnt; /* # of statefile alloc retries */
} cpr_t;
/*
* c_flags definitions
*/
#define C_SUSPENDING 0x01
#define C_RESUMING 0x02
#define C_COMPRESSING 0x04
#define C_REUSABLE 0x08
#define C_ERROR 0x10
/*
* definitions for c_substate. It works together w/ c_flags to determine which
* stages the CPR is at.
*/
#define C_ST_SUSPEND_BEGIN 0
#define C_ST_MP_OFFLINE 1
#define C_ST_STOP_USER_THREADS 2
#define C_ST_PM_REATTACH_NOINVOL 3
#define C_ST_DISABLE_UFS_LOGGING 4
#define C_ST_STATEF_ALLOC 5
#define C_ST_SUSPEND_DEVICES 6
#define C_ST_STOP_KERNEL_THREADS 7
#define C_ST_SETPROPS_1 8
#define C_ST_DUMP 9
#define C_ST_SETPROPS_0 10
#define C_ST_DUMP_NOSPC 11
#define C_ST_REUSABLE 12
#define C_ST_NODUMP 13
#define C_ST_MP_PAUSED 14
#define C_MAX_ALLOC_RETRY 4
#define CPR_PROM_SAVE 0
#define CPR_PROM_RESTORE 1
#define CPR_PROM_FREE 2
/*
*/
#define CPRBUFSZ 0x20000
/*
* cpr statefile I/O on a block device begins after the disk label
* and bootblock (primarily for disk slices that start at cyl 0);
* the offset should be at least (label size + bootblock size = 8k)
*/
#define CPR_SPEC_OFFSET 16384
/*
* arena scan info
*/
struct cpr_walkinfo {
int mapflag;
int ranges;
};
/*
* Value used by cpr, found in devi_cpr_flags
*/
/*
* Values used to differentiate between suspend to disk and suspend to ram
* in cpr_suspend and cpr_resume
*/
#define CPR_TORAM 3
#define CPR_TODISK 4
#ifndef _ASM
extern char *cpr_build_statefile_path(void);
extern char *cpr_enumerate_promprops(char **, size_t *);
extern char *cpr_get_statefile_prom_path(void);
extern int cpr_contig_pages(vnode_t *, int);
extern int cpr_default_setup(int);
extern int cpr_get_reusable_mode(void);
extern int cpr_main(int);
extern int cpr_mp_offline(void);
extern int cpr_mp_online(void);
extern int cpr_open_deffile(int, vnode_t **);
extern int cpr_read_cprinfo(int, char *, char *);
extern int cpr_read_phys_page(int, uint_t, int *);
extern int cpr_resume_devices(dev_info_t *, int);
extern int cpr_set_properties(int);
extern int cpr_statefile_is_spec(void);
extern int cpr_statefile_offset(void);
extern int cpr_stop_kernel_threads(void);
extern int cpr_threads_are_stopped(void);
extern int cpr_stop_user_threads(void);
extern int cpr_suspend_devices(dev_info_t *);
extern int cpr_validate_definfo(int);
extern int cpr_update_nvram(cprop_t *);
extern int cpr_write_deffile(cdef_t *);
extern int i_cpr_alloc_bitmaps(void);
extern int i_cpr_dump_sensitive_kpages(vnode_t *);
extern int i_cpr_save_sensitive_kpages(void);
extern ssize_t cpr_get_machdep_len(int);
extern void cpr_clear_definfo(void);
extern void cpr_restore_time(void);
extern void cpr_save_time(void);
extern void cpr_signal_user(int sig);
extern void cpr_spinning_bar(void);
extern void cpr_start_user_threads(void);
extern void cpr_stat_cleanup(void);
extern void cpr_stat_event_end(char *, cpr_time_t *);
extern void cpr_stat_event_print(void);
extern void cpr_stat_event_start(char *, cpr_time_t *);
extern void cpr_stat_record_events(void);
extern void cpr_tod_fault_reset(void);
extern void i_cpr_bitmap_cleanup(void);
extern void i_cpr_stop_other_cpus(void);
extern void i_cpr_alloc_cpus(void);
extern void i_cpr_free_cpus(void);
/*PRINTFLIKE2*/
extern cpr_time_t wholecycle_tv;
extern int cpr_reusable_mode;
#endif /* _ASM */
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_CPR_H */