/** 
 * fxfb_utility.c
 *
 * Copyright (C) 2015 Fuji Xerox Co.,Ltd. All rights reserved.
 *
 * This 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, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * 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., 59
 * Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The full GNU General Public License is included in this distribution in the
 * file called COPYING.
 */
#ifdef __KERNEL__
 #include <linux/stddef.h>
 #include <linux/types.h>
 #include <linux/ctype.h>
#else
 #include <stddef.h>
 #include <stdint.h>
 #include <ctype.h>
#endif
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <linux/platform_device.h>
#include <linux/semaphore.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/atomic.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/spinlock.h>
#include <linux/fb.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/time.h>
#include <linux/fxprivate/fxnvram.h>
#include "fxfb_drv.h"
#define _FXFBCU 0x01
#define _FXFBCL 0x02
#define fxfb_islower(c) (((c) & (_FXFBCL)) != 0)
#define fxfb_isupper(c) (((c) & (_FXFBCU)) != 0)
FXFB_ALIGN_BYTES(static const char errstr_EPERM[]) = "EPERM:Operation not permitted";
FXFB_ALIGN_BYTES(static const char errstr_ENOENT[]) = "ENOENT:No such file or directory";
FXFB_ALIGN_BYTES(static const char errstr_ESRCH[]) = "ESRCH:No such process";
FXFB_ALIGN_BYTES(static const char errstr_EINTR[]) = "EINTR:Interrupted function call";
FXFB_ALIGN_BYTES(static const char errstr_EIO[]) = "EIO:I/O error";
FXFB_ALIGN_BYTES(static const char errstr_ENXIO[]) = "ENXIO:No such device or address";
FXFB_ALIGN_BYTES(static const char errstr_E2BIG[]) = "E2BIG:Argument list too long";
FXFB_ALIGN_BYTES(static const char errstr_ENOEXEC[]) = "ENOEXEC:Exec format error";
FXFB_ALIGN_BYTES(static const char errstr_EBADF[]) = "EBADF:Bad file descriptor";
FXFB_ALIGN_BYTES(static const char errstr_ECHILD[]) = "ECHILD:No child processes";
FXFB_ALIGN_BYTES(static const char errstr_EAGAIN[]) = "EAGAIN:Try again";
FXFB_ALIGN_BYTES(static const char errstr_ENOMEM[]) = "ENOMEM:Not enough space";
FXFB_ALIGN_BYTES(static const char errstr_EACCES[]) = "EACCES:Permission denied";
FXFB_ALIGN_BYTES(static const char errstr_EFAULT[]) = "EFAULT:Bad address";
FXFB_ALIGN_BYTES(static const char errstr_ENOTBLK[]) = "ENOTBLK:Block device required";
FXFB_ALIGN_BYTES(static const char errstr_EBUSY[]) = "EBUSY:Device or resource busy";
FXFB_ALIGN_BYTES(static const char errstr_EEXIST[]) = "EEXIST:File exists";
FXFB_ALIGN_BYTES(static const char errstr_EXDEV[]) = "EXDEV:Cross-device link";
FXFB_ALIGN_BYTES(static const char errstr_ENODEV[]) = "ENODEV:No such device";
FXFB_ALIGN_BYTES(static const char errstr_ENOTDIR[]) = "ENOTDIR:Not a directory";
FXFB_ALIGN_BYTES(static const char errstr_EISDIR[]) = "EISDIR:Is a directory";
FXFB_ALIGN_BYTES(static const char errstr_EINVAL[]) = "EINVAL:Invalid argument";
FXFB_ALIGN_BYTES(static const char errstr_ENFILE[]) = "ENFILE:File table overflow";
FXFB_ALIGN_BYTES(static const char errstr_EMFILE[]) = "EMFILE:Too many open files";
FXFB_ALIGN_BYTES(static const char errstr_ENOTTY[]) = "ENOTTY:Not a typewriter";
FXFB_ALIGN_BYTES(static const char errstr_ETXTBSY[]) = "ETXTBSY:Text file busy";
FXFB_ALIGN_BYTES(static const char errstr_EFBIG[]) = "EFBIG:File too large";
FXFB_ALIGN_BYTES(static const char errstr_ENOSPC[]) = "ENOSPC:No space left on device";
FXFB_ALIGN_BYTES(static const char errstr_ESPIPE[]) = "ESPIPE:Illegal seek";
FXFB_ALIGN_BYTES(static const char errstr_EROFS[]) = "EROFS:Read-only file system";
FXFB_ALIGN_BYTES(static const char errstr_EMLINK[]) = "EMLINK:Too many links";
FXFB_ALIGN_BYTES(static const char errstr_EPIPE[]) = "EPIPE:Broken pipe";
FXFB_ALIGN_BYTES(static const char errstr_EDOM[]) = "EDOM:Math argument out of domain of func";
FXFB_ALIGN_BYTES(static const char errstr_ERANGE[]) = "ERANGE:Math result not representable";
FXFB_ALIGN_BYTES(static const char errstr_EDEADLK[]) = "EDEADLK:Resource deadlock would occur";
FXFB_ALIGN_BYTES(static const char errstr_ENAMETOOLONG[]) = "ENAMETOOLONG:File name too long";
FXFB_ALIGN_BYTES(static const char errstr_ENOLCK[]) = "ENOLCK:No record locks available";
FXFB_ALIGN_BYTES(static const char errstr_ENOSYS[]) = "ENOSYS:Function not implemented";
FXFB_ALIGN_BYTES(static const char errstr_ENOTEMPTY[]) = "ENOTEMPTY:Directory not empty";
FXFB_ALIGN_BYTES(static const char errstr_ELOOP[]) = "ELOOP:Too many symbolic links encountered";
FXFB_ALIGN_BYTES(static const char errstr_EWOULDBLOCK[]) = "EWOULDBLOCK:Operation would block";
FXFB_ALIGN_BYTES(static const char errstr_ENOMSG[]) = "ENOMSG:No message of desired type";
FXFB_ALIGN_BYTES(static const char errstr_EIDRM[]) = "EIDRM:Identifier removed";
FXFB_ALIGN_BYTES(static const char errstr_ECHRNG[]) = "ECHRNG:Channel number out of range";
FXFB_ALIGN_BYTES(static const char errstr_EL2NSYNC[]) = "EL2NSYNC:Level 2 not synchronized";
FXFB_ALIGN_BYTES(static const char errstr_EL3HLT[]) = "EL3HLT:Level 3 halted";
FXFB_ALIGN_BYTES(static const char errstr_EL3RST[]) = "EL3RST:Level 3 reset";
FXFB_ALIGN_BYTES(static const char errstr_ELNRNG[]) = "ELNRNG:Link number out of range";
FXFB_ALIGN_BYTES(static const char errstr_EUNATCH[]) = "EUNATCH:Protocol driver not attached";
FXFB_ALIGN_BYTES(static const char errstr_ENOCSI[]) = "ENOCSI:No CSI structure available";
FXFB_ALIGN_BYTES(static const char errstr_EL2HLT[]) = "EL2HLT:Level 2 halted";
FXFB_ALIGN_BYTES(static const char errstr_EBADE[]) = "EBADE:Invalid exchange";
FXFB_ALIGN_BYTES(static const char errstr_EBADR[]) = "EBADR:Invalid request descriptor";
FXFB_ALIGN_BYTES(static const char errstr_EXFULL[]) = "EXFULL:Exchange full";
FXFB_ALIGN_BYTES(static const char errstr_ENOANO[]) = "ENOANO:No anode";
FXFB_ALIGN_BYTES(static const char errstr_EBADRQC[]) = "EBADRQC:Invalid request code";
FXFB_ALIGN_BYTES(static const char errstr_EBADSLT[]) = "EBADSLT:Invalid slot";
FXFB_ALIGN_BYTES(static const char errstr_EBFONT[]) = "EBFONT:Bad font file format";
FXFB_ALIGN_BYTES(static const char errstr_ENOSTR[]) = "ENOSTR:Device not a stream";
FXFB_ALIGN_BYTES(static const char errstr_ENODATA[]) = "ENODATA:No data available";
FXFB_ALIGN_BYTES(static const char errstr_ETIME[]) = "ETIME:Timer expired";
FXFB_ALIGN_BYTES(static const char errstr_ENOSR[]) = "ENOSR:Out of streams resources";
FXFB_ALIGN_BYTES(static const char errstr_ENONET[]) = "ENONET:Machine is not on the network";
FXFB_ALIGN_BYTES(static const char errstr_ENOPKG[]) = "ENOPKG:Package not installed";
FXFB_ALIGN_BYTES(static const char errstr_EREMOTE[]) = "EREMOTE:Object is remote";
FXFB_ALIGN_BYTES(static const char errstr_ENOLINK[]) = "ENOLINK:Link has been severed";
FXFB_ALIGN_BYTES(static const char errstr_EADV[]) = "EADV:Advertise error";
FXFB_ALIGN_BYTES(static const char errstr_ESRMNT[]) = "ESRMNT:Srmount error";
FXFB_ALIGN_BYTES(static const char errstr_ECOMM[]) = "ECOMM:Communication error on send";
FXFB_ALIGN_BYTES(static const char errstr_EPROTO[]) = "EPROTO:Protocol error";
FXFB_ALIGN_BYTES(static const char errstr_EMULTIHOP[]) = "EMULTIHOP:Multihop attempted";
FXFB_ALIGN_BYTES(static const char errstr_EDOTDOT[]) = "EDOTDOT:RFS specific error";
FXFB_ALIGN_BYTES(static const char errstr_EBADMSG[]) = "EBADMSG:Not a data message";
FXFB_ALIGN_BYTES(static const char errstr_EOVERFLOW[]) = "EOVERFLOW:Value too large for defined data type";
FXFB_ALIGN_BYTES(static const char errstr_ENOTUNIQ[]) = "ENOTUNIQ:Name not unique on network";
FXFB_ALIGN_BYTES(static const char errstr_EBADFD[]) = "EBADFD:File descriptor in bad state";
FXFB_ALIGN_BYTES(static const char errstr_EREMCHG[]) = "EREMCHG:Remote address changed";
FXFB_ALIGN_BYTES(static const char errstr_ELIBACC[]) = "ELIBACC:Can not access a needed shared library";
FXFB_ALIGN_BYTES(static const char errstr_ELIBBAD[]) = "ELIBBAD:Accessing a corrupted shared library";
FXFB_ALIGN_BYTES(static const char errstr_ELIBSCN[]) = "ELIBSCN:.lib section in a.out corrupted";
FXFB_ALIGN_BYTES(static const char errstr_ELIBMAX[]) = "ELIBMAX:Attempting to link in too many shared libraries";
FXFB_ALIGN_BYTES(static const char errstr_ELIBEXEC[]) = "ELIBEXEC:Cannot exec a shared library directly";
FXFB_ALIGN_BYTES(static const char errstr_EILSEQ[]) = "EILSEQ:Illegal byte sequence";
FXFB_ALIGN_BYTES(static const char errstr_ERESTART[]) = "ERESTART:Interrupted system call should be restarted";
FXFB_ALIGN_BYTES(static const char errstr_ESTRPIPE[]) = "ESTRPIPE:Streams pipe error";
FXFB_ALIGN_BYTES(static const char errstr_EUSERS[]) = "EUSERS:Too many users";
FXFB_ALIGN_BYTES(static const char errstr_ENOTSOCK[]) = "ENOTSOCK:Socket operation on non-socket";
FXFB_ALIGN_BYTES(static const char errstr_EDESTADDRREQ[]) = "EDESTADDRREQ:Destination address required";
FXFB_ALIGN_BYTES(static const char errstr_EMSGSIZE[]) = "EMSGSIZE:Message too long";
FXFB_ALIGN_BYTES(static const char errstr_EPROTOTYPE[]) = "EPROTOTYPE:Protocol wrong type for socket";
FXFB_ALIGN_BYTES(static const char errstr_ENOPROTOOPT[]) = "ENOPROTOOPT:Protocol not available";
FXFB_ALIGN_BYTES(static const char errstr_EPROTONOSUPPORT[]) = "EPROTONOSUPPORT:Protocol not supported";
FXFB_ALIGN_BYTES(static const char errstr_ESOCKTNOSUPPORT[]) = "ESOCKTNOSUPPORT:Socket type not supported";
FXFB_ALIGN_BYTES(static const char errstr_EOPNOTSUPP[]) = "EOPNOTSUPP:Operation not supported on transport endpoint";
FXFB_ALIGN_BYTES(static const char errstr_EPFNOSUPPORT[]) = "EPFNOSUPPORT:Protocol family not supported";
FXFB_ALIGN_BYTES(static const char errstr_EAFNOSUPPORT[]) = "EAFNOSUPPORT:Address family not supported by protocol";
FXFB_ALIGN_BYTES(static const char errstr_EADDRINUSE[]) = "EADDRINUSE:Address already in use";
FXFB_ALIGN_BYTES(static const char errstr_EADDRNOTAVAIL[]) = "EADDRNOTAVAIL:Cannot assign requested address";
FXFB_ALIGN_BYTES(static const char errstr_ENETDOWN[]) = "ENETDOWN:Network is down";
FXFB_ALIGN_BYTES(static const char errstr_ENETUNREACH[]) = "ENETUNREACH:Network is unreachable";
FXFB_ALIGN_BYTES(static const char errstr_ENETRESET[]) = "ENETRESET:Network dropped connection because of reset";
FXFB_ALIGN_BYTES(static const char errstr_ECONNABORTED[]) = "ECONNABORTED:Software caused connection abort";
FXFB_ALIGN_BYTES(static const char errstr_ECONNRESET[]) = "ECONNRESET:Connection reset by peer";
FXFB_ALIGN_BYTES(static const char errstr_ENOBUFS[]) = "ENOBUFS:No buffer space available";
FXFB_ALIGN_BYTES(static const char errstr_EISCONN[]) = "EISCONN:Transport endpoint is already connected";
FXFB_ALIGN_BYTES(static const char errstr_ENOTCONN[]) = "ENOTCONN:Transport endpoint is not connected";
FXFB_ALIGN_BYTES(static const char errstr_ESHUTDOWN[]) = "ESHUTDOWN:Cannot send after transport endpoint shutdown";
FXFB_ALIGN_BYTES(static const char errstr_ETOOMANYREFS[]) = "ETOOMANYREFS:Too many references: cannot splice";
FXFB_ALIGN_BYTES(static const char errstr_ETIMEDOUT[]) = "ETIMEDOUT:Connection timed out";
FXFB_ALIGN_BYTES(static const char errstr_ECONNREFUSED[]) = "ECONNREFUSED:Connection refused";
FXFB_ALIGN_BYTES(static const char errstr_EHOSTDOWN[]) = "EHOSTDOWN:Host is down";
FXFB_ALIGN_BYTES(static const char errstr_EHOSTUNREACH[]) = "EHOSTUNREACH:No route to host";
FXFB_ALIGN_BYTES(static const char errstr_EALREADY[]) = "EALREADY:Operation already in progress";
FXFB_ALIGN_BYTES(static const char errstr_EINPROGRESS[]) = "EINPROGRESS:Operation now in progress";
FXFB_ALIGN_BYTES(static const char errstr_ESTALE[]) = "ESTALE:Stale NFS file handle";
FXFB_ALIGN_BYTES(static const char errstr_EUCLEAN[]) = "EUCLEAN:Structure needs cleaning";
FXFB_ALIGN_BYTES(static const char errstr_ENOTNAM[]) = "ENOTNAM:Not a XENIX named type file";
FXFB_ALIGN_BYTES(static const char errstr_ENAVAIL[]) = "ENAVAIL:No XENIX semaphores available";
FXFB_ALIGN_BYTES(static const char errstr_EISNAM[]) = "EISNAM:Is a named type file";
FXFB_ALIGN_BYTES(static const char errstr_EREMOTEIO[]) = "EREMOTEIO:Remote I/O error";
FXFB_ALIGN_BYTES(static const char errstr_EDQUOT[]) = "EDQUOT:Quota exceeded";
FXFB_ALIGN_BYTES(static const char errstr_ENOMEDIUM[]) = "ENOMEDIUM:No medium found";
FXFB_ALIGN_BYTES(static const char errstr_EMEDIUMTYPE[]) = "EMEDIUMTYPE:Wrong medium type";
FXFB_ALIGN_BYTES(static const char errstr_ECANCELED[]) = "ECANCELED:Operation Canceled";
FXFB_ALIGN_BYTES(static const char errstr_ENOKEY[]) = "ENOKEY:Required key not available";
FXFB_ALIGN_BYTES(static const char errstr_EKEYEXPIRED[]) = "EKEYEXPIRED:Key has expired";
FXFB_ALIGN_BYTES(static const char errstr_EKEYREVOKED[]) = "EKEYREVOKED:Key has been revoked";
FXFB_ALIGN_BYTES(static const char errstr_EKEYREJECTED[]) = "EKEYREJECTED:Key was rejected by service";
FXFB_ALIGN_BYTES(static const char errstr_EOWNERDEAD[]) = "EOWNERDEAD:Owner died";
FXFB_ALIGN_BYTES(static const char errstr_ENOTRECOVERABLE[]) = "ENOTRECOVERABLE:State not recoverable";
FXFB_ALIGN_BYTES(static const char errstr_ERFKILL[]) = "ERFKILL:Operation not possible due to RF-kill";
FXFB_ALIGN_BYTES(static const char errstr_EHWPOISON[]) = "EHWPOISON:Memory page has hardware error";
FXFB_ALIGN_BYTES(static const char errstr_UNKNOWN[]) = "Unknown error";
FXFB_ALIGN_BYTES(static fxfb_error_strings fxfb_error_string_table[]) = {
 { EPERM , errstr_EPERM } ,
 { ENOENT , errstr_ENOENT } ,
 { ESRCH , errstr_ESRCH } ,
 { EINTR , errstr_EINTR } ,
 { EIO , errstr_EIO } ,
 { ENXIO , errstr_ENXIO } ,
 { E2BIG , errstr_E2BIG } ,
 { ENOEXEC , errstr_ENOEXEC } ,
 { EBADF , errstr_EBADF } ,
 { ECHILD , errstr_ECHILD } ,
 { EAGAIN , errstr_EAGAIN } ,
 { ENOMEM , errstr_ENOMEM } ,
 { EACCES , errstr_EACCES } ,
 { EFAULT , errstr_EFAULT } ,
 { ENOTBLK , errstr_ENOTBLK } ,
 { EBUSY , errstr_EBUSY } ,
 { EEXIST , errstr_EEXIST } ,
 { EXDEV , errstr_EXDEV } ,
 { ENODEV , errstr_ENODEV } ,
 { ENOTDIR , errstr_ENOTDIR } ,
 { EISDIR , errstr_EISDIR } ,
 { EINVAL , errstr_EINVAL } ,
 { ENFILE , errstr_ENFILE } ,
 { EMFILE , errstr_EMFILE } ,
 { ENOTTY , errstr_ENOTTY } ,
 { ETXTBSY , errstr_ETXTBSY } ,
 { EFBIG , errstr_EFBIG } ,
 { ENOSPC , errstr_ENOSPC } ,
 { ESPIPE , errstr_ESPIPE } ,
 { EROFS , errstr_EROFS } ,
 { EMLINK , errstr_EMLINK } ,
 { EPIPE , errstr_EPIPE } ,
 { EDOM , errstr_EDOM } ,
 { ERANGE , errstr_ERANGE } ,
 { EDEADLK , errstr_EDEADLK } ,
 { ENAMETOOLONG , errstr_ENAMETOOLONG } ,
 { ENOLCK , errstr_ENOLCK } ,
 { ENOSYS , errstr_ENOSYS } ,
 { ENOTEMPTY , errstr_ENOTEMPTY } ,
 { ELOOP , errstr_ELOOP } ,
 { ENOMSG , errstr_ENOMSG } ,
 { EIDRM , errstr_EIDRM } ,
 { ECHRNG , errstr_ECHRNG } ,
 { EL2NSYNC , errstr_EL2NSYNC } ,
 { EL3HLT , errstr_EL3HLT } ,
 { EL3RST , errstr_EL3RST } ,
 { ELNRNG , errstr_ELNRNG } ,
 { EUNATCH , errstr_EUNATCH } ,
 { ENOCSI , errstr_ENOCSI } ,
 { EL2HLT , errstr_EL2HLT } ,
 { EBADE , errstr_EBADE } ,
 { EBADR , errstr_EBADR } ,
 { EXFULL , errstr_EXFULL } ,
 { ENOANO , errstr_ENOANO } ,
 { EBADRQC , errstr_EBADRQC } ,
 { EBADSLT , errstr_EBADSLT } ,
 { EBFONT , errstr_EBFONT } ,
 { ENOSTR , errstr_ENOSTR } ,
 { ENODATA , errstr_ENODATA } ,
 { ETIME , errstr_ETIME } ,
 { ENOSR , errstr_ENOSR } ,
 { ENONET , errstr_ENONET } ,
 { ENOPKG , errstr_ENOPKG } ,
 { EREMOTE , errstr_EREMOTE } ,
 { ENOLINK , errstr_ENOLINK } ,
 { EADV , errstr_EADV } ,
 { ESRMNT , errstr_ESRMNT } ,
 { ECOMM , errstr_ECOMM } ,
 { EPROTO , errstr_EPROTO } ,
 { EMULTIHOP , errstr_EMULTIHOP } ,
 { EDOTDOT , errstr_EDOTDOT } ,
 { EBADMSG , errstr_EBADMSG } ,
 { EOVERFLOW , errstr_EOVERFLOW } ,
 { ENOTUNIQ , errstr_ENOTUNIQ } ,
 { EBADFD , errstr_EBADFD } ,
 { EREMCHG , errstr_EREMCHG } ,
 { ELIBACC , errstr_ELIBACC } ,
 { ELIBBAD , errstr_ELIBBAD } ,
 { ELIBSCN , errstr_ELIBSCN } ,
 { ELIBMAX , errstr_ELIBMAX } ,
 { ELIBEXEC , errstr_ELIBEXEC } ,
 { EILSEQ , errstr_EILSEQ } ,
 { ERESTART , errstr_ERESTART } ,
 { ESTRPIPE , errstr_ESTRPIPE } ,
 { EUSERS , errstr_EUSERS } ,
 { ENOTSOCK , errstr_ENOTSOCK } ,
 { EDESTADDRREQ , errstr_EDESTADDRREQ } ,
 { EMSGSIZE , errstr_EMSGSIZE } ,
 { EPROTOTYPE , errstr_EPROTOTYPE } ,
 { ENOPROTOOPT , errstr_ENOPROTOOPT } ,
 { EPROTONOSUPPORT , errstr_EPROTONOSUPPORT } ,
 { ESOCKTNOSUPPORT , errstr_ESOCKTNOSUPPORT } ,
 { EOPNOTSUPP , errstr_EOPNOTSUPP } ,
 { EPFNOSUPPORT , errstr_EPFNOSUPPORT } ,
 { EAFNOSUPPORT , errstr_EAFNOSUPPORT } ,
 { EADDRINUSE , errstr_EADDRINUSE } ,
 { EADDRNOTAVAIL , errstr_EADDRNOTAVAIL } ,
 { ENETDOWN , errstr_ENETDOWN } ,
 { ENETUNREACH , errstr_ENETUNREACH } ,
 { ENETRESET , errstr_ENETRESET } ,
 { ECONNABORTED , errstr_ECONNABORTED } ,
 { ECONNRESET , errstr_ECONNRESET } ,
 { ENOBUFS , errstr_ENOBUFS } ,
 { EISCONN , errstr_EISCONN } ,
 { ENOTCONN , errstr_ENOTCONN } ,
 { ESHUTDOWN , errstr_ESHUTDOWN } ,
 { ETOOMANYREFS , errstr_ETOOMANYREFS } ,
 { ETIMEDOUT , errstr_ETIMEDOUT } ,
 { ECONNREFUSED , errstr_ECONNREFUSED } ,
 { EHOSTDOWN , errstr_EHOSTDOWN } ,
 { EHOSTUNREACH , errstr_EHOSTUNREACH } ,
 { EALREADY , errstr_EALREADY } ,
 { EINPROGRESS , errstr_EINPROGRESS } ,
 { ESTALE , errstr_ESTALE } ,
 { EUCLEAN , errstr_EUCLEAN } ,
 { ENOTNAM , errstr_ENOTNAM } ,
 { ENAVAIL , errstr_ENAVAIL } ,
 { EISNAM , errstr_EISNAM } ,
 { EREMOTEIO , errstr_EREMOTEIO } ,
 { EDQUOT , errstr_EDQUOT } ,
 { ENOMEDIUM , errstr_ENOMEDIUM } ,
 { EMEDIUMTYPE , errstr_EMEDIUMTYPE } ,
 { ECANCELED , errstr_ECANCELED } ,
 { ENOKEY , errstr_ENOKEY } ,
 { EKEYEXPIRED , errstr_EKEYEXPIRED } ,
 { EKEYREVOKED , errstr_EKEYREVOKED } ,
 { EKEYREJECTED , errstr_EKEYREJECTED } ,
 { EOWNERDEAD , errstr_EOWNERDEAD } ,
 { ENOTRECOVERABLE , errstr_ENOTRECOVERABLE } ,
 { ERFKILL , errstr_ERFKILL } ,
 { EHWPOISON , errstr_EHWPOISON } ,
 { EHWPOISON , errstr_EHWPOISON }
};
#define ERRSTR_TBLSZ (sizeof(fxfb_error_string_table) / sizeof(fxfb_error_strings))
FXFB_ALIGN_BYTES(static struct fb_info *pFxfb_fb_info) = (struct fb_info *)NULL;
FXFB_ALIGN_BYTES(static timeWatcher stopWatchTimes);
#define FXFB_SEC_TIME 1000
#define FXFB_SPINLOCK_WAIT_TIME 3000
#define FXFB_MUTEX_WAIT_TIME 3000
#define FXFB_ERRBUF_SIZE 32
void put_function_start_message(const char *pFileName,const char *pFunction,int32_t lineNo)
{
#ifndef FXFB_DRVINFO
 UNUSED(pFileName);
 UNUSED(lineNo);
#endif
#ifdef FXFB_DRVINFO
 PUTFXFBMSG("%s %s() %d enter.\n",FILENAMES(pFileName),pFunction,lineNo);
#else
 PUTFXFBMSG("%s() enter.\n",pFunction);
#endif
}
void put_error_message(const char *pFileName,const char *pFunction,int32_t lineNo,int32_t retCode)
{
#ifndef FXFB_DRVINFO
 UNUSED(pFileName);
 UNUSED(lineNo);
#endif
#ifdef FXFB_DRVINFO
 if (retCode != FXFB_SUCCESS) {
  PUTFXFBMSG("%s %s() %d exit : execute failure(%d:%s).\n",FILENAMES(pFileName),
          pFunction,lineNo,retCode,fxfb_strerror(retCode));
 } else {
  PUTFXFBMSG("%s %s() %d exit : execute succeeded.\n",FILENAMES(pFileName),pFunction,lineNo);
 }
#else
 if (retCode != FXFB_SUCCESS) {
  PUTFXFBMSG("%s() exit : execute failure(%d:%s).\n",pFunction,retCode,fxfb_strerror(retCode));
 } else {
  PUTFXFBMSG("%s() exit : execute succeeded.\n",pFunction);
 }
#endif
}
static unsigned char fxfb_tolower(unsigned char c)
{
 if (fxfb_isupper(c)) {
  c -= 'A'-'a';
 }
 return c;
}
static unsigned char fxfb_toupper(unsigned char c)
{
 if (fxfb_islower(c)) {
  c -= 'a'-'A';
 }
 return c;
}
char *fxfb_strlwr(char *s)
{
 FXFB_ALIGN_BYTES(char *p) = s;
 while (*s) {
  *s = (char)fxfb_tolower((unsigned char)*s);
  s++;
 }
 return p;
}
char *fxfb_strupr(char *s)
{
 FXFB_ALIGN_BYTES(char *p) = s;
 while (*s) {
  *s = (char)fxfb_toupper((unsigned char)*s);
  s++;
 }
 return p;
}
void fxfb_set_fb_info(struct fb_info *pfb_info)
{
 if(pfb_info)
  pFxfb_fb_info = pfb_info;
}
struct fb_info *fxfb_get_fb_info(void)
{
 return pFxfb_fb_info;
}
void reset_fxfb_fbinfo(void)
{
 pFxfb_fb_info = (struct fb_info *)NULL;
}
PFXFBLOCAL fxfb_get_local_info(void)
{
 FXFB_ALIGN_BYTES(struct fb_info *p);
 p = pFxfb_fb_info;
 if (p == (struct fb_info *)NULL) {
  return (PFXFBLOCAL)NULL;
 }
 return (PFXFBLOCAL)p->par;
}
void fxfb_setErrorCode(int32_t errCode)
{
 FXFB_ALIGN_BYTES(PFXFBLOCAL q);
 q = fxfb_get_local_info();
 if (q == (PFXFBLOCAL)NULL) {
  return;
 }
 q->fxfb_errno = errCode;
}
int32_t fxfb_getErrorCode(void)
{
 FXFB_ALIGN_BYTES(PFXFBLOCAL q);
 q = fxfb_get_local_info();
 if (q == (PFXFBLOCAL)NULL) {
  return -ENODEV;
 }
 return q->fxfb_errno;
}
void *kernel_malloc(size_t mallocSize,int32_t *pDiff,void **ppAlloc)
{
 size_t sz;
 FXFB_ALIGN_BYTES(void *p);
 FXFB_ALIGN_BYTES(void *q);
 if ((int32_t)mallocSize <= 0) {
  PUTFXFBMSG("%s() %s\n",__FUNCTION__,"invalid argument.");
  fxfb_setErrorCode(EINVAL);
  return (void *)NULL;
 }
 if ( pDiff == (int *)NULL ) {
  PUTFXFBMSG("%s() %s\n",__FUNCTION__,"invalid argument.");
  fxfb_setErrorCode(EINVAL);
  return (void *)NULL;
 }
 if ( ppAlloc == (void *)NULL || *ppAlloc == (void *)NULL ) {
  PUTFXFBMSG("%s() %s\n",__FUNCTION__,"invalid argument.");
  fxfb_setErrorCode(EINVAL);
  return (void *)NULL;
 }
 mallocSize += sizeof(unsigned int);
 CORRECT_ADDR_BOUNDARY(mallocSize);
 sz = mallocSize;
 p = kzalloc(sz,GFP_KERNEL);
 if (p == (void *)NULL) {
  PUTFXFBMSG("%s() %s\n",__FUNCTION__,"not enough space.");
  fxfb_setErrorCode(ENOMEM);
  return (void *)NULL;
 }
 *ppAlloc = p;
 q = p;
 CORRECT_ADDR_BOUNDARY(q);
 if ( (uint32_t)q != (uint32_t)p ) {
  *pDiff = (int)((uint32_t)q - (uint32_t)p);
 } else {
  *pDiff = 0;
 }
 return q;
}
void fxfb_spin_lock(PFXFBLOCAL pFxfb_local,unsigned long *pFlags,int32_t *pLocked)
{
 FXFB_ALIGN_BYTES(volatile unsigned long irqFlags);
 FXFB_ALIGN_BYTES(volatile int32_t loopCount) = 0;
 do {
  *pLocked = rt_spin_trylock_irqsave((spinlock_t *)&pFxfb_local->fxfb_spinLock,(unsigned long *)&irqFlags);
  *pFlags = irqFlags;
  if (!*pLocked && loopCount < FXFB_SPINLOCK_WAIT_TIME) {
   ms_wait(1);
   loopCount++;
  }
 } while (!*pLocked && loopCount < FXFB_SPINLOCK_WAIT_TIME);
 if (loopCount >= FXFB_SPINLOCK_WAIT_TIME) {
  PUTFXFBMSG("%s\n","spin_trylock_irqsave() time out.");
  fxfb_setErrorCode(ETIMEDOUT);
 }
}
void fxfb_mutex_lock(PFXFBLOCAL pFxfb_local,int32_t *pLocked)
{
 mutex_lock(&pFxfb_local->fxfb_lock);
 *pLocked = 1;
}
void fxfb_spin_unlock(PFXFBLOCAL pFxfb_local,unsigned long flags,int32_t locked)
{
 if (locked) {
  spin_unlock_irqrestore(&pFxfb_local->fxfb_spinLock, flags);
 }
}
void fxfb_mutex_unlock(PFXFBLOCAL pFxfb_local,int32_t locked)
{
 if (locked) {
  mutex_unlock(&pFxfb_local->fxfb_lock);
 }
}
static void print_watch_time(const char *pMsg,timeWatcher *pTimeDiff)
{
 unsigned long msec,usecM,usec;
 if (pTimeDiff->stop.tv_sec > pTimeDiff->start.tv_sec) {
  msec = (unsigned long)(FXFB_SEC_TIME * (pTimeDiff->stop.tv_sec - pTimeDiff->start.tv_sec));
 } else {
  msec = (unsigned long)(FXFB_SEC_TIME * (pTimeDiff->start.tv_sec - pTimeDiff->stop.tv_sec));
 }
 if (pTimeDiff->stop.tv_usec > pTimeDiff->start.tv_usec) {
  usecM = (unsigned long)((pTimeDiff->stop.tv_usec - pTimeDiff->start.tv_usec) / FXFB_SEC_TIME);
  usec = (unsigned long)((pTimeDiff->stop.tv_usec - pTimeDiff->start.tv_usec) % FXFB_SEC_TIME);
 } else {
  usecM = (unsigned long)((pTimeDiff->start.tv_usec - pTimeDiff->stop.tv_usec) / FXFB_SEC_TIME);
  usec = (unsigned long)((pTimeDiff->start.tv_usec - pTimeDiff->stop.tv_usec) % FXFB_SEC_TIME);
 }
 msec += usecM;
 if (pMsg) {
  PUTFXFBMSG("%s elapsed time : %ld.%ld millisec \n" , pMsg , msec , usec);
 } else {
  PUTFXFBMSG("elapsed time : %ld.%ld millisec \n", msec , usec);
 }
}
void stopWatch(const char *pMsg,int operation)
{
 switch (operation) {
  case RESET_STOP_WATCH:
  memset((void *)&stopWatchTimes,(int)0,(size_t)sizeof(timeWatcher));
  break;
  case START_STOP_WATCH:
  do_gettimeofday(&stopWatchTimes.start);
  break;
  case ENDOF_STOP_WATCH:
  do_gettimeofday(&stopWatchTimes.stop);
  break;
  case PRINT_STOP_WATCH:
  print_watch_time(pMsg,&stopWatchTimes);
  break;
  default:
  break;
 }
}
static int32_t fxfb_errno_cmp(const void *p0, const void *p1)
{
 PERRSTRINGS pErrTable0,pErrTable1;
 pErrTable0 = (PERRSTRINGS)p0;
 pErrTable1 = (PERRSTRINGS)p1;
 return pErrTable0->fxfb_errno - pErrTable1->fxfb_errno;
}
static char *error_strings_binarySearch(int32_t errNo,
      PERRSTRINGS pErrorStringTable,int (*cmp)(const void *p,const void *q))
{
 int32_t left = 0;
 int32_t right = ERRSTR_TBLSZ;
 int32_t mid;
 int32_t retVal;
 fxfb_error_strings unknown_error_strings;
 unknown_error_strings.fxfb_errno = errNo;
 unknown_error_strings.pErrorContents = (char *)NULL;
 while (left <= right) {
  mid = (left + right) / 2 ;
  retVal = cmp((void *)&pErrorStringTable[mid],(void *)&unknown_error_strings);
  if (retVal == 0) {
   return (char *)pErrorStringTable[mid].pErrorContents;
  } else if (retVal < 0) {
   left = mid + 1;
  } else {
   right = mid - 1;
  }
 }
 return (char *)NULL;
}
char *fxfb_strerror(int32_t errNo)
{
 FXFB_ALIGN_BYTES(char *p);
 FXFB_ALIGN_BYTES(char *q);
 FXFB_ALIGN_BYTES(static char unknown_error_buffer[FXFB_ERRBUF_SIZE]);
 if (errNo < 0) {
  errNo = TWOS_COMPLEMENT(errNo);
 }
 (void)snprintf(unknown_error_buffer,(FXFB_ERRBUF_SIZE - 1 ),"Unknown error %d",errNo);
 q = &unknown_error_buffer[0];
 if (errNo == 0) {
  strcpy(unknown_error_buffer,"No error");
  return (char *)&unknown_error_buffer[0];
 }
 p = error_strings_binarySearch(errNo,&fxfb_error_string_table[0],fxfb_errno_cmp);
 if (!p) {
  p = q;
 }
 return p;
}
#ifdef FXFB_ERRSTRERROR_DEBUG
void debug_fxfb_strerror(void)
{
 FXFBMSG("EPERM : %d : %s\n",EPERM,fxfb_strerror(EPERM));
 FXFBMSG("ENOENT : %d : %s\n",ENOENT,fxfb_strerror(ENOENT));
 FXFBMSG("ESRCH : %d : %s\n",ESRCH,fxfb_strerror(ESRCH));
 FXFBMSG("EINTR : %d : %s\n",EINTR,fxfb_strerror(EINTR));
 FXFBMSG("EIO : %d : %s\n",EIO,fxfb_strerror(EIO));
 FXFBMSG("ENXIO : %d : %s\n",ENXIO,fxfb_strerror(ENXIO));
 FXFBMSG("E2BIG : %d : %s\n",E2BIG,fxfb_strerror(E2BIG));
 FXFBMSG("ENOEXEC : %d : %s\n",ENOEXEC,fxfb_strerror(ENOEXEC));
 FXFBMSG("EBADF : %d : %s\n",EBADF,fxfb_strerror(EBADF));
 FXFBMSG("ECHILD : %d : %s\n",ECHILD,fxfb_strerror(ECHILD));
 FXFBMSG("EAGAIN : %d : %s\n",EAGAIN,fxfb_strerror(EAGAIN));
 FXFBMSG("ENOMEM : %d : %s\n",ENOMEM,fxfb_strerror(ENOMEM));
 FXFBMSG("EACCES : %d : %s\n",EACCES,fxfb_strerror(EACCES));
 FXFBMSG("EFAULT : %d : %s\n",EFAULT,fxfb_strerror(EFAULT));
 FXFBMSG("ENOTBLK : %d : %s\n",ENOTBLK,fxfb_strerror(ENOTBLK));
 FXFBMSG("EBUSY : %d : %s\n",EBUSY,fxfb_strerror(EBUSY));
 FXFBMSG("EEXIST : %d : %s\n",EEXIST,fxfb_strerror(EEXIST));
 FXFBMSG("EXDEV : %d : %s\n",EXDEV,fxfb_strerror(EXDEV));
 FXFBMSG("ENODEV : %d : %s\n",ENODEV,fxfb_strerror(ENODEV));
 FXFBMSG("ENOTDIR : %d : %s\n",ENOTDIR,fxfb_strerror(ENOTDIR));
 FXFBMSG("EISDIR : %d : %s\n",EISDIR,fxfb_strerror(EISDIR));
 FXFBMSG("EINVAL : %d : %s\n",EINVAL,fxfb_strerror(EINVAL));
 FXFBMSG("ENFILE : %d : %s\n",ENFILE,fxfb_strerror(ENFILE));
 FXFBMSG("EMFILE : %d : %s\n",EMFILE,fxfb_strerror(EMFILE));
 FXFBMSG("ENOTTY : %d : %s\n",ENOTTY,fxfb_strerror(ENOTTY));
 FXFBMSG("ETXTBSY : %d : %s\n",ETXTBSY,fxfb_strerror(ETXTBSY));
 FXFBMSG("EFBIG : %d : %s\n",EFBIG,fxfb_strerror(EFBIG));
 FXFBMSG("ENOSPC : %d : %s\n",ENOSPC,fxfb_strerror(ENOSPC));
 FXFBMSG("ESPIPE : %d : %s\n",ESPIPE,fxfb_strerror(ESPIPE));
 FXFBMSG("EROFS : %d : %s\n",EROFS,fxfb_strerror(EROFS));
 FXFBMSG("EMLINK : %d : %s\n",EMLINK,fxfb_strerror(EMLINK));
 FXFBMSG("EPIPE : %d : %s\n",EPIPE,fxfb_strerror(EPIPE));
 FXFBMSG("EDOM : %d : %s\n",EDOM,fxfb_strerror(EDOM));
 FXFBMSG("ERANGE : %d : %s\n",ERANGE,fxfb_strerror(ERANGE));
 FXFBMSG("EDEADLK : %d : %s\n",EDEADLK,fxfb_strerror(EDEADLK));
 FXFBMSG("ENAMETOOLONG : %d : %s\n",ENAMETOOLONG,fxfb_strerror(ENAMETOOLONG));
 FXFBMSG("ENOLCK : %d : %s\n",ENOLCK,fxfb_strerror(ENOLCK));
 FXFBMSG("ENOSYS : %d : %s\n",ENOSYS,fxfb_strerror(ENOSYS));
 FXFBMSG("ENOTEMPTY : %d : %s\n",ENOTEMPTY,fxfb_strerror(ENOTEMPTY));
 FXFBMSG("ELOOP : %d : %s\n",ELOOP,fxfb_strerror(ELOOP));
 FXFBMSG("ENOMSG : %d : %s\n",ENOMSG,fxfb_strerror(ENOMSG));
 FXFBMSG("EIDRM : %d : %s\n",EIDRM,fxfb_strerror(EIDRM));
 FXFBMSG("ECHRNG : %d : %s\n",ECHRNG,fxfb_strerror(ECHRNG));
 FXFBMSG("EL2NSYNC : %d : %s\n",EL2NSYNC,fxfb_strerror(EL2NSYNC));
 FXFBMSG("EL3HLT : %d : %s\n",EL3HLT,fxfb_strerror(EL3HLT));
 FXFBMSG("EL3RST : %d : %s\n",EL3RST,fxfb_strerror(EL3RST));
 FXFBMSG("ELNRNG : %d : %s\n",ELNRNG,fxfb_strerror(ELNRNG));
 FXFBMSG("EUNATCH : %d : %s\n",EUNATCH,fxfb_strerror(EUNATCH));
 FXFBMSG("ENOCSI : %d : %s\n",ENOCSI,fxfb_strerror(ENOCSI));
 FXFBMSG("EL2HLT : %d : %s\n",EL2HLT,fxfb_strerror(EL2HLT));
 FXFBMSG("EBADE : %d : %s\n",EBADE,fxfb_strerror(EBADE));
 FXFBMSG("EBADR : %d : %s\n",EBADR,fxfb_strerror(EBADR));
 FXFBMSG("EXFULL : %d : %s\n",EXFULL,fxfb_strerror(EXFULL));
 FXFBMSG("ENOANO : %d : %s\n",ENOANO,fxfb_strerror(ENOANO));
 FXFBMSG("EBADRQC : %d : %s\n",EBADRQC,fxfb_strerror(EBADRQC));
 FXFBMSG("EBADSLT : %d : %s\n",EBADSLT,fxfb_strerror(EBADSLT));
 FXFBMSG("EBFONT : %d : %s\n",EBFONT,fxfb_strerror(EBFONT));
 FXFBMSG("ENOSTR : %d : %s\n",ENOSTR,fxfb_strerror(ENOSTR));
 FXFBMSG("ENODATA : %d : %s\n",ENODATA,fxfb_strerror(ENODATA));
 FXFBMSG("ETIME : %d : %s\n",ETIME,fxfb_strerror(ETIME));
 FXFBMSG("ENOSR : %d : %s\n",ENOSR,fxfb_strerror(ENOSR));
 FXFBMSG("ENONET : %d : %s\n",ENONET,fxfb_strerror(ENONET));
 FXFBMSG("ENOPKG : %d : %s\n",ENOPKG,fxfb_strerror(ENOPKG));
 FXFBMSG("EREMOTE : %d : %s\n",EREMOTE,fxfb_strerror(EREMOTE));
 FXFBMSG("ENOLINK : %d : %s\n",ENOLINK,fxfb_strerror(ENOLINK));
 FXFBMSG("EADV : %d : %s\n",EADV,fxfb_strerror(EADV));
 FXFBMSG("ESRMNT : %d : %s\n",ESRMNT,fxfb_strerror(ESRMNT));
 FXFBMSG("ECOMM : %d : %s\n",ECOMM,fxfb_strerror(ECOMM));
 FXFBMSG("EPROTO : %d : %s\n",EPROTO,fxfb_strerror(EPROTO));
 FXFBMSG("EMULTIHOP : %d : %s\n",EMULTIHOP,fxfb_strerror(EMULTIHOP));
 FXFBMSG("EDOTDOT : %d : %s\n",EDOTDOT,fxfb_strerror(EDOTDOT));
 FXFBMSG("EBADMSG : %d : %s\n",EBADMSG,fxfb_strerror(EBADMSG));
 FXFBMSG("EOVERFLOW : %d : %s\n",EOVERFLOW,fxfb_strerror(EOVERFLOW));
 FXFBMSG("ENOTUNIQ : %d : %s\n",ENOTUNIQ,fxfb_strerror(ENOTUNIQ));
 FXFBMSG("EBADFD : %d : %s\n",EBADFD,fxfb_strerror(EBADFD));
 FXFBMSG("EREMCHG : %d : %s\n",EREMCHG,fxfb_strerror(EREMCHG));
 FXFBMSG("ELIBACC : %d : %s\n",ELIBACC,fxfb_strerror(ELIBACC));
 FXFBMSG("ELIBBAD : %d : %s\n",ELIBBAD,fxfb_strerror(ELIBBAD));
 FXFBMSG("ELIBSCN : %d : %s\n",ELIBSCN,fxfb_strerror(ELIBSCN));
 FXFBMSG("ELIBMAX : %d : %s\n",ELIBMAX,fxfb_strerror(ELIBMAX));
 FXFBMSG("ELIBEXEC : %d : %s\n",ELIBEXEC,fxfb_strerror(ELIBEXEC));
 FXFBMSG("EILSEQ : %d : %s\n",EILSEQ,fxfb_strerror(EILSEQ));
 FXFBMSG("ERESTART : %d : %s\n",ERESTART,fxfb_strerror(ERESTART));
 FXFBMSG("ESTRPIPE : %d : %s\n",ESTRPIPE,fxfb_strerror(ESTRPIPE));
 FXFBMSG("EUSERS : %d : %s\n",EUSERS,fxfb_strerror(EUSERS));
 FXFBMSG("ENOTSOCK : %d : %s\n",ENOTSOCK,fxfb_strerror(ENOTSOCK));
 FXFBMSG("EDESTADDRREQ : %d : %s\n",EDESTADDRREQ,fxfb_strerror(EDESTADDRREQ));
 FXFBMSG("EMSGSIZE : %d : %s\n",EMSGSIZE,fxfb_strerror(EMSGSIZE));
 FXFBMSG("EPROTOTYPE : %d : %s\n",EPROTOTYPE,fxfb_strerror(EPROTOTYPE));
 FXFBMSG("ENOPROTOOPT : %d : %s\n",ENOPROTOOPT,fxfb_strerror(ENOPROTOOPT));
 FXFBMSG("EPROTONOSUPPORT : %d : %s\n",EPROTONOSUPPORT,fxfb_strerror(EPROTONOSUPPORT));
 FXFBMSG("ESOCKTNOSUPPORT : %d : %s\n",ESOCKTNOSUPPORT,fxfb_strerror(ESOCKTNOSUPPORT));
 FXFBMSG("EOPNOTSUPP : %d : %s\n",EOPNOTSUPP,fxfb_strerror(EOPNOTSUPP));
 FXFBMSG("EPFNOSUPPORT : %d : %s\n",EPFNOSUPPORT,fxfb_strerror(EPFNOSUPPORT));
 FXFBMSG("EAFNOSUPPORT : %d : %s\n",EAFNOSUPPORT,fxfb_strerror(EAFNOSUPPORT));
 FXFBMSG("EADDRINUSE : %d : %s\n",EADDRINUSE,fxfb_strerror(EADDRINUSE));
 FXFBMSG("EADDRNOTAVAIL : %d : %s\n",EADDRNOTAVAIL,fxfb_strerror(EADDRNOTAVAIL));
 FXFBMSG("ENETDOWN : %d : %s\n",ENETDOWN,fxfb_strerror(ENETDOWN));
 FXFBMSG("ENETUNREACH : %d : %s\n",ENETUNREACH,fxfb_strerror(ENETUNREACH));
 FXFBMSG("ENETRESET : %d : %s\n",ENETRESET,fxfb_strerror(ENETRESET));
 FXFBMSG("ECONNABORTED : %d : %s\n",ECONNABORTED,fxfb_strerror(ECONNABORTED));
 FXFBMSG("ECONNRESET : %d : %s\n",ECONNRESET,fxfb_strerror(ECONNRESET));
 FXFBMSG("ENOBUFS : %d : %s\n",ENOBUFS,fxfb_strerror(ENOBUFS));
 FXFBMSG("EISCONN : %d : %s\n",EISCONN,fxfb_strerror(EISCONN));
 FXFBMSG("ENOTCONN : %d : %s\n",ENOTCONN,fxfb_strerror(ENOTCONN));
 FXFBMSG("ESHUTDOWN : %d : %s\n",ESHUTDOWN,fxfb_strerror(ESHUTDOWN));
 FXFBMSG("ETOOMANYREFS : %d : %s\n",ETOOMANYREFS,fxfb_strerror(ETOOMANYREFS));
 FXFBMSG("ETIMEDOUT : %d : %s\n",ETIMEDOUT,fxfb_strerror(ETIMEDOUT));
 FXFBMSG("ECONNREFUSED : %d : %s\n",ECONNREFUSED,fxfb_strerror(ECONNREFUSED));
 FXFBMSG("EHOSTDOWN : %d : %s\n",EHOSTDOWN,fxfb_strerror(EHOSTDOWN));
 FXFBMSG("EHOSTUNREACH : %d : %s\n",EHOSTUNREACH,fxfb_strerror(EHOSTUNREACH));
 FXFBMSG("EALREADY : %d : %s\n",EALREADY,fxfb_strerror(EALREADY));
 FXFBMSG("EINPROGRESS : %d : %s\n",EINPROGRESS,fxfb_strerror(EINPROGRESS));
 FXFBMSG("ESTALE : %d : %s\n",ESTALE,fxfb_strerror(ESTALE));
 FXFBMSG("EUCLEAN : %d : %s\n",EUCLEAN,fxfb_strerror(EUCLEAN));
 FXFBMSG("ENOTNAM : %d : %s\n",ENOTNAM,fxfb_strerror(ENOTNAM));
 FXFBMSG("ENAVAIL : %d : %s\n",ENAVAIL,fxfb_strerror(ENAVAIL));
 FXFBMSG("EISNAM : %d : %s\n",EISNAM,fxfb_strerror(EISNAM));
 FXFBMSG("EREMOTEIO : %d : %s\n",EREMOTEIO,fxfb_strerror(EREMOTEIO));
 FXFBMSG("EDQUOT : %d : %s\n",EDQUOT,fxfb_strerror(EDQUOT));
 FXFBMSG("ENOMEDIUM : %d : %s\n",ENOMEDIUM,fxfb_strerror(ENOMEDIUM));
 FXFBMSG("EMEDIUMTYPE : %d : %s\n",EMEDIUMTYPE,fxfb_strerror(EMEDIUMTYPE));
 FXFBMSG("ECANCELED : %d : %s\n",ECANCELED,fxfb_strerror(ECANCELED));
 FXFBMSG("ENOKEY : %d : %s\n",ENOKEY,fxfb_strerror(ENOKEY));
 FXFBMSG("EKEYEXPIRED : %d : %s\n",EKEYEXPIRED,fxfb_strerror(EKEYEXPIRED));
 FXFBMSG("EKEYREVOKED : %d : %s\n",EKEYREVOKED,fxfb_strerror(EKEYREVOKED));
 FXFBMSG("EKEYREJECTED : %d : %s\n",EKEYREJECTED,fxfb_strerror(EKEYREJECTED));
 FXFBMSG("EOWNERDEAD : %d : %s\n",EOWNERDEAD,fxfb_strerror(EOWNERDEAD));
 FXFBMSG("ENOTRECOVERABLE : %d : %s\n",ENOTRECOVERABLE,fxfb_strerror(ENOTRECOVERABLE));
 FXFBMSG("ERFKILL : %d : %s\n",ERFKILL,fxfb_strerror(ERFKILL));
 FXFBMSG("EHWPOISON : %d : %s\n",EHWPOISON,fxfb_strerror(EHWPOISON));
}
#endif
void fxfb_nvm_err_countup(int err_type)
{
 unsigned char read_data;
 unsigned char write_data;
 unsigned int offset;
 int ret;
 switch (err_type) {
 case FXFB_NVM_ERR_VSYNC:
  offset = KERNEL_NVRAM_FXFB_ERR_OFFSET;
  break;
 case FXFB_NVM_ERR_FIFO_UNDERRUN:
  offset = KERNEL_NVRAM_FXFB_ERR_OFFSET + 1;
  break;
 case FXFB_NVM_ERR_LDD_TIMEOUT:
  offset = KERNEL_NVRAM_FXFB_ERR_OFFSET + 2;
  break;
 default:
  FXFB_ERR("unknown err_type (type:%d)\n", err_type);
  return;
 }
 ret = nvram_kread(&read_data, offset, 1);
 if (ret < 0) {
  FXFB_ERR("nvram_kread failed (type:%d, ret:%d)\n", err_type, ret);
  return;
 }
 if (0xff <= read_data) return;
 write_data = read_data + 1;
 ret = nvram_kwrite(&write_data, offset, 1);
 if (ret < 0) {
  FXFB_ERR("nvram_kwrite failed (type:%d, ret:%d)\n", err_type, ret);
  return;
 }
 return;
}
int fxfb_nvm_err_get_count(int err_type)
{
 unsigned char read_data;
 unsigned int offset;
 int ret;
 switch (err_type) {
 case FXFB_NVM_ERR_VSYNC:
  offset = KERNEL_NVRAM_FXFB_ERR_OFFSET;
  break;
 case FXFB_NVM_ERR_FIFO_UNDERRUN:
  offset = KERNEL_NVRAM_FXFB_ERR_OFFSET + 1;
  break;
 case FXFB_NVM_ERR_LDD_TIMEOUT:
  offset = KERNEL_NVRAM_FXFB_ERR_OFFSET + 2;
  break;
 default:
  FXFB_ERR("unknown err_type (type:%d)\n", err_type);
  return -EINVAL;
 }
 ret = nvram_kread(&read_data, offset, 1);
 if (ret < 0) {
  FXFB_ERR("nvram_kread failed (type:%d, ret:%d)\n", err_type, ret);
  return ret;
 }
 return (int)read_data;
}
