FreeBSD kernel pms device code
smmisc.c
Go to the documentation of this file.
1/*******************************************************************************
2*Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved.
3*
4*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5*that the following conditions are met:
6*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7*following disclaimer.
8*2. Redistributions in binary form must reproduce the above copyright notice,
9*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10*with the distribution.
11*
12*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20
21********************************************************************************/
22#include <sys/cdefs.h>
23__FBSDID("$FreeBSD$");
24#include <dev/pms/config.h>
25
29
31
35
39
43
44FORCEINLINE void*
45sm_memset(void *s, int c, bit32 n)
46{
47/* bit32 i;
48
49 char *dst = (char *)s;
50 for (i=0; i < n; i++)
51 {
52 dst[i] = (char) c;
53 }
54 return (void *)(&dst[i-n]);
55*/
56 return memset(s, c, n);
57}
58
59FORCEINLINE void*
60sm_memcpy(void *dst, const void *src, bit32 count)
61{
62/*
63 bit32 x;
64 unsigned char *dst1 = (unsigned char *)dst;
65 unsigned char *src1 = (unsigned char *)src;
66
67 for (x=0; x < count; x++)
68 dst1[x] = src1[x];
69
70 return dst;
71*/
72 return memcpy(dst, src, count);
73}
74
75osGLOBAL char
76*sm_strncpy(char *dst, const char *src, bit32 len)
77{
78/* char *ret = dst;
79 do {
80 if (!len--)
81 return ret;
82 } while ((*dst++ = *src++));
83 while (len--)
84 *dst++ = 0;
85 return ret;
86*/ return strncpy(dst, src, len);
87}
88
90osGLOBAL void
91smhexdump(const char *ptitle, bit8 *pbuf, size_t len)
92{
93 size_t i;
94 SM_DBG1(("%s - smhexdump(len=%d):\n", ptitle, (int)len));
95 if (!pbuf)
96 {
97 SM_DBG1(("pbuf is NULL\n"));
98 return;
99 }
100 for (i = 0; i < len; )
101 {
102 if (len - i > 4)
103 {
104 SM_DBG1((" 0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", pbuf[i], pbuf[i+1], pbuf[i+2], pbuf[i+3]));
105 i += 4;
106 }
107 else
108 {
109 SM_DBG1((" 0x%02x,", pbuf[i]));
110 i++;
111 }
112 }
113 SM_DBG1(("\n"));
114}
115
116
#define osGLOBAL
Definition: ostypes.h:147
unsigned int bit32
Definition: ostypes.h:99
#define FORCEINLINE
Definition: ostypes.h:86
unsigned char bit8
Definition: ostypes.h:97
The file defines the constants, data structure, and functions defined by LL API.
The file defines the declaration of tSDK APIs.
The file defines the declaration of OS APIs.
#define SM_DBG1(format)
Definition: smdefs.h:533
osGLOBAL void smhexdump(const char *ptitle, bit8 *pbuf, size_t len)
Definition: smmisc.c:91
__FBSDID("$FreeBSD$")
osGLOBAL char * sm_strncpy(char *dst, const char *src, bit32 len)
Definition: smmisc.c:76
FORCEINLINE void * sm_memset(void *s, int c, bit32 n)
Definition: smmisc.c:45
FORCEINLINE void * sm_memcpy(void *dst, const void *src, bit32 count)
Definition: smmisc.c:60