Home | History | Annotate | Line # | Download | only in sysmon
      1  1.48  riastrad /* $NetBSD: sysmon_envsysvar.h,v 1.48 2021/12/31 11:05:41 riastradh Exp $ */
      2   1.1   xtraeme 
      3   1.1   xtraeme /*-
      4  1.27   xtraeme  * Copyright (c) 2007, 2008 Juan Romero Pardines.
      5   1.1   xtraeme  * All rights reserved.
      6   1.1   xtraeme  *
      7   1.1   xtraeme  * Redistribution and use in source and binary forms, with or without
      8   1.1   xtraeme  * modification, are permitted provided that the following conditions
      9   1.1   xtraeme  * are met:
     10   1.1   xtraeme  * 1. Redistributions of source code must retain the above copyright
     11   1.1   xtraeme  *    notice, this list of conditions and the following disclaimer.
     12   1.1   xtraeme  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1   xtraeme  *    notice, this list of conditions and the following disclaimer in the
     14   1.1   xtraeme  *    documentation and/or other materials provided with the distribution.
     15   1.1   xtraeme  *
     16  1.20   xtraeme  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.20   xtraeme  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.20   xtraeme  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.20   xtraeme  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.20   xtraeme  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.20   xtraeme  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.20   xtraeme  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.20   xtraeme  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.20   xtraeme  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.20   xtraeme  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26   1.1   xtraeme  */
     27   1.1   xtraeme 
     28   1.1   xtraeme #ifndef _DEV_SYSMON_ENVSYSVAR_H_
     29   1.1   xtraeme #define _DEV_SYSMON_ENVSYSVAR_H_
     30   1.1   xtraeme 
     31   1.1   xtraeme #include <sys/param.h>
     32   1.1   xtraeme #include <sys/types.h>
     33   1.1   xtraeme #include <sys/conf.h>
     34   1.1   xtraeme #include <sys/kernel.h>
     35   1.1   xtraeme #include <sys/systm.h>
     36   1.1   xtraeme #include <sys/mutex.h>
     37   1.1   xtraeme #include <sys/workqueue.h>
     38   1.8   xtraeme #include <sys/condvar.h>
     39   1.1   xtraeme 
     40   1.1   xtraeme #include <dev/sysmon/sysmonvar.h>
     41   1.1   xtraeme #include <prop/proplib.h>
     42   1.1   xtraeme 
     43  1.45  macallan #ifdef _KERNEL_OPT
     44  1.44  macallan #include "opt_envsys.h"
     45  1.45  macallan #endif
     46  1.44  macallan 
     47  1.37  pgoyette enum sme_descr_type {
     48  1.17   xtraeme 	SME_DESC_UNITS = 1,
     49  1.17   xtraeme 	SME_DESC_STATES,
     50  1.17   xtraeme 	SME_DESC_DRIVE_STATES,
     51  1.43  pgoyette 	SME_DESC_BATTERY_CAPACITY,
     52  1.43  pgoyette 	SME_DESC_INDICATOR
     53  1.17   xtraeme };
     54  1.17   xtraeme 
     55   1.1   xtraeme #ifdef ENVSYS_DEBUG
     56   1.1   xtraeme #define DPRINTF(x)	printf x
     57   1.1   xtraeme #else
     58   1.1   xtraeme #define DPRINTF(x)
     59   1.1   xtraeme #endif
     60   1.1   xtraeme 
     61   1.1   xtraeme #ifdef ENVSYS_OBJECTS_DEBUG
     62   1.1   xtraeme #define DPRINTFOBJ(x)	printf x
     63   1.1   xtraeme #else
     64   1.1   xtraeme #define DPRINTFOBJ(x)
     65   1.1   xtraeme #endif
     66   1.1   xtraeme 
     67  1.24   xtraeme /*
     68  1.24   xtraeme  * Default timeout value for the callouts if no specified.
     69  1.24   xtraeme  */
     70  1.24   xtraeme #define SME_EVENTS_DEFTIMEOUT	30
     71  1.24   xtraeme 
     72  1.48  riastrad /*
     73  1.24   xtraeme  * struct used by a sysmon envsys event.
     74  1.24   xtraeme  */
     75   1.1   xtraeme typedef struct sme_event {
     76  1.27   xtraeme 	struct work		see_wk;
     77   1.6   xtraeme 	LIST_ENTRY(sme_event) 	see_list;
     78  1.24   xtraeme 	struct sysmon_envsys	*see_sme;	/* device associated */
     79  1.24   xtraeme 	struct penvsys_state	see_pes;	/* our power envsys */
     80  1.24   xtraeme 	envsys_data_t		*see_edata;	/* our sensor data */
     81  1.24   xtraeme 	int			see_type;	/* type of the event */
     82  1.43  pgoyette 	int			see_evstate;	/* state of prev event */
     83  1.43  pgoyette 	int			see_evvalue;	/* value of prev event */
     84   1.5   xtraeme 	int 			see_flags;	/* see above */
     85  1.28  pgoyette #define SEE_EVENT_WORKING	0x0001 		/* This event is busy */
     86   1.1   xtraeme } sme_event_t;
     87   1.1   xtraeme 
     88  1.48  riastrad /*
     89  1.24   xtraeme  * struct by a sysmon envsys event set by a driver.
     90  1.24   xtraeme  */
     91   1.1   xtraeme typedef struct sme_event_drv {
     92  1.24   xtraeme 	struct sysmon_envsys	*sed_sme;
     93  1.24   xtraeme 	prop_dictionary_t	sed_sdict;
     94  1.24   xtraeme 	envsys_data_t		*sed_edata;
     95  1.24   xtraeme 	int			sed_powertype;
     96   1.1   xtraeme } sme_event_drv_t;
     97   1.1   xtraeme 
     98  1.37  pgoyette struct sme_descr_entry {
     99  1.17   xtraeme 	int 		type;
    100  1.17   xtraeme 	int 		crittype;
    101  1.17   xtraeme 	const char 	*desc;
    102  1.17   xtraeme };
    103  1.17   xtraeme 
    104  1.48  riastrad /*
    105  1.24   xtraeme  * common stuff.
    106  1.24   xtraeme  */
    107  1.27   xtraeme extern	kmutex_t sme_global_mtx; 	/* for the sme linked list and dict */
    108  1.35  pgoyette extern	prop_dictionary_t sme_propd;	/* the global sensor dictionary */
    109   1.1   xtraeme 
    110  1.48  riastrad /*
    111  1.24   xtraeme  * linked list for the sysmon envsys devices.
    112  1.24   xtraeme  */
    113  1.41      matt LIST_HEAD(sysmon_envsys_lh, sysmon_envsys);
    114  1.41      matt extern	struct sysmon_envsys_lh sysmon_envsys_list;
    115   1.1   xtraeme 
    116  1.48  riastrad /*
    117  1.24   xtraeme  * functions to handle sysmon envsys devices.
    118  1.24   xtraeme  */
    119   1.1   xtraeme int	sme_update_dictionary(struct sysmon_envsys *);
    120  1.39  pgoyette int	sme_update_sensor_dictionary(prop_object_t, envsys_data_t *, bool);
    121   1.1   xtraeme int	sme_userset_dictionary(struct sysmon_envsys *,
    122   1.1   xtraeme 			       prop_dictionary_t, prop_array_t);
    123  1.20   xtraeme prop_dictionary_t sme_sensor_dictionary_get(prop_array_t, const char *);
    124  1.23   xtraeme struct	sysmon_envsys *sysmon_envsys_find(const char *);
    125  1.27   xtraeme void	sysmon_envsys_acquire(struct sysmon_envsys *, bool);
    126  1.27   xtraeme void	sysmon_envsys_release(struct sysmon_envsys *, bool);
    127   1.1   xtraeme 
    128  1.48  riastrad /*
    129  1.24   xtraeme  * functions to handle sysmon envsys events.
    130  1.24   xtraeme  */
    131  1.24   xtraeme int	sme_event_register(prop_dictionary_t, envsys_data_t *,
    132  1.30  pgoyette 			   struct sysmon_envsys *, sysmon_envsys_lim_t *,
    133  1.31  pgoyette 			   uint32_t, int, int);
    134  1.24   xtraeme int	sme_event_unregister(struct sysmon_envsys *, const char *, int);
    135  1.42  pgoyette int	sme_event_unregister_sensor(struct sysmon_envsys *, envsys_data_t *);
    136  1.24   xtraeme void	sme_event_unregister_all(struct sysmon_envsys *);
    137   1.1   xtraeme void	sme_event_drvadd(void *);
    138  1.24   xtraeme int	sme_events_init(struct sysmon_envsys *);
    139  1.24   xtraeme void	sme_events_destroy(struct sysmon_envsys *);
    140  1.47     ozaki void	sme_events_halt_callout(struct sysmon_envsys *);
    141   1.1   xtraeme void	sme_events_check(void *);
    142  1.33  pgoyette void	sme_events_worker(struct work *, void *);
    143  1.33  pgoyette void	sme_deliver_event(sme_event_t *);
    144  1.36  pgoyette int	sme_update_limits(struct sysmon_envsys *, envsys_data_t *);
    145  1.38  pgoyette void	sme_schedule_callout(struct sysmon_envsys *);
    146   1.1   xtraeme 
    147  1.48  riastrad /*
    148  1.24   xtraeme  * common functions to create/update objects in a dictionary.
    149  1.24   xtraeme  */
    150   1.9   xtraeme int	sme_sensor_upbool(prop_dictionary_t, const char *, bool);
    151   1.9   xtraeme int	sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
    152   1.9   xtraeme int	sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
    153   1.9   xtraeme int	sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
    154   1.8   xtraeme 
    155  1.37  pgoyette const struct sme_descr_entry *sme_find_table_entry(enum sme_descr_type, int);
    156  1.40  pgoyette const struct sme_descr_entry * sme_find_table_desc(enum sme_descr_type,
    157  1.40  pgoyette 						   const char *);
    158  1.17   xtraeme 
    159   1.1   xtraeme #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
    160