/* 2008-12-06: File added by Sony Corporation */
/*
 *  include/linux/snsc_panic.h -- Sony NSC SPI interface
 *
 *  Copyright 2007 Sony Corporation.
 *
 *  This program is free software; you can redistribute  it and/or modify it
 *  under  the terms of  the GNU General  Public License as published by the
 *  Free Software Foundation;  either version 2 of the  License.
 *
 *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
 *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
 *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
 *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *  You should have received a copy of the  GNU General Public License along
 *  with this program; if not, write  to the Free Software Foundation, Inc.,
 *  675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _LINUX_SNSC_PANIC_H_
#define _LINUX_SNSC_PANIC_H_

#ifdef __KERNEL__

/*---- struct/enum definitions ---------------------------*/
/*
 * snsc_panic_cause_t::class
 */
typedef enum {
        SNSC_PANIC_DRV = 1,
        SNSC_PANIC_NET,
        SNSC_PANIC_FS,
        SNSC_PANIC_MM,
        SNSC_PANIC_OTHER
        /*
         * add class name with snsc_panic_xxx_t
         */
} snsc_panic_class_t;

/*
 * drv,
 * one of snsc_panic_cause_t::u
 */
typedef struct {
       int major;
       int minor;
       void *priv;
} snsc_panic_drv_t;

/*
 * net,
 * one of snsc_panic_cause_t::u
 */
typedef struct {
        /*
         * add members for net.
         */
        void *priv;
} snsc_panic_net_t;

/*
 * fs,
 * one of snsc_panic_cause_t::u
 */
typedef struct {
        /*
         * add members for fs.
         */
        void *priv;
} snsc_panic_fs_t;

/*
 * mm,
 * one of snsc_panic_cause_t::u
 */
typedef struct {
        /*
         * add members for mm.
         */
        void *priv;
} snsc_panic_mm_t;

/*
 * other,
 * one of snsc_panic_cause_t::u
 */
typedef struct {
        void *priv;
} snsc_panic_other_t;

/*
 * SNSC_PANIC_GET_CAUSE return param
 */
typedef struct {
        snsc_panic_class_t class;
        union {
                snsc_panic_drv_t      drv;
                snsc_panic_net_t      net;
                snsc_panic_fs_t       fs;
                snsc_panic_mm_t       mm;
                snsc_panic_other_t    other;
        } u;
        const char *file;
        int line;
} snsc_panic_cause_t;

/*---- API definitions ---------------------------*/

#ifdef CONFIG_SNSC_PANIC_HOOK

extern snsc_panic_cause_t snsc_panic_cause;

#define SNSC_PANIC_SET_CAUSE(a, b)                                            \
{                                                                             \
        /* can't set twice */                                                 \
        if (snsc_panic_cause.class == 0) {                                    \
                switch (a) {                                                  \
                case SNSC_PANIC_DRV:                                          \
                        memcpy(&snsc_panic_cause.u.drv, b, sizeof(*b));       \
                        break;                                                \
                case SNSC_PANIC_NET:                                          \
                        memcpy(&snsc_panic_cause.u.net, b, sizeof(*b));       \
                        break;                                                \
                case SNSC_PANIC_FS:                                           \
                        memcpy(&snsc_panic_cause.u.fs, b, sizeof(*b));        \
                        break;                                                \
                case SNSC_PANIC_MM:                                           \
                        memcpy(&snsc_panic_cause.u.mm, b, sizeof(*b));        \
                        break;                                                \
                case SNSC_PANIC_OTHER:                                        \
                        memcpy(&snsc_panic_cause.u.other, b, sizeof(*b));     \
                        break;                                                \
                default:                                                      \
                        /* do nothing */                                      \
                        break;                                                \
                }                                                             \
                snsc_panic_cause.class = a;                                   \
                snsc_panic_cause.file = __FILE__;                             \
                snsc_panic_cause.line = __LINE__;                             \
        }                                                                     \
} while (0)

#define SNSC_PANIC_GET_CAUSE() \
    (snsc_panic_cause.class?(const snsc_panic_cause_t *)&snsc_panic_cause:NULL)

#else /* CONFIG_SNSC_PANIC_HOOK */

#define SNSC_PANIC_SET_CAUSE(a, b)
#define SNSC_PANIC_GET_CAUSE()                                  (NULL)

#endif /* CONFIG_SNSC_PANIC_HOOK */
#endif /* __KERNEL__ */
#endif /* !_LINUX_SNSC_PANIC_H_ */
