1 /*
2  * This file was generated automatically by ExtUtils::ParseXS version 3.45 from the
3  * contents of Intrs.xs. Do not edit this file, edit Intrs.xs instead.
4  *
5  *    ANY CHANGES MADE HERE WILL BE LOST!
6  *
7  */
8 
9 #line 1 "Intrs.xs"
10 /*
11  * CDDL HEADER START
12  *
13  * The contents of this file are subject to the terms of the
14  * Common Development and Distribution License (the "License").
15  * You may not use this file except in compliance with the License.
16  *
17  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
18  * or http://www.opensolaris.org/os/licensing.
19  * See the License for the specific language governing permissions
20  * and limitations under the License.
21  *
22  * When distributing Covered Code, include this CDDL HEADER in each
23  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
24  * If applicable, add the following below this CDDL HEADER, with the
25  * fields enclosed by brackets "[]" replaced with your own identifying
26  * information: Portions Copyright [yyyy] [name of copyright owner]
27  *
28  * CDDL HEADER END
29  */
30 
31 /*
32  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
33  */
34 
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <sys/pci.h>
38 #include <fcntl.h>
39 #include <unistd.h>
40 #include <stropts.h>
41 #include <stdio.h>
42 #include <errno.h>
43 
44 /* Non-shipping header - see Makefile.PL */
45 #include <sys/pci_tools.h>
46 
47 #include "EXTERN.h"
48 #if __GNUC__ >= 5
49 #include "perl.h"
50 #else
51 #define _Thread_local
52 #include "perl.h"
53 #undef _Thread_local
54 #undef PERL_GET_CONTEXT
55 #undef PERL_SET_CONTEXT
56 #define PERL_GET_CONTEXT	PTHREAD_GETSPECIFIC(PL_thr_key)
57 #define PERL_SET_CONTEXT(t)	Perl_set_context((void*)t)
58 #endif
59 #include "XSUB.h"
60 
61 static int
62 open_dev(char *path)
63 {
64 	char intrpath[MAXPATHLEN];
65 
66 	(void) strcpy(intrpath, "/devices");
67 	(void) strcat(intrpath, path);
68 	(void) strcat(intrpath, ":intr");
69 	return (open(intrpath, O_RDWR));
70 }
71 
72 #line 73 "Intrs.c"
73 #ifndef PERL_UNUSED_VAR
74 #  define PERL_UNUSED_VAR(var) if (0) var = var
75 #endif
76 
77 #ifndef dVAR
78 #  define dVAR		dNOOP
79 #endif
80 
81 
82 /* This stuff is not part of the API! You have been warned. */
83 #ifndef PERL_VERSION_DECIMAL
84 #  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
85 #endif
86 #ifndef PERL_DECIMAL_VERSION
87 #  define PERL_DECIMAL_VERSION \
88 	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
89 #endif
90 #ifndef PERL_VERSION_GE
91 #  define PERL_VERSION_GE(r,v,s) \
92 	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
93 #endif
94 #ifndef PERL_VERSION_LE
95 #  define PERL_VERSION_LE(r,v,s) \
96 	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
97 #endif
98 
99 /* XS_INTERNAL is the explicit static-linkage variant of the default
100  * XS macro.
101  *
102  * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
103  * "STATIC", ie. it exports XSUB symbols. You probably don't want that
104  * for anything but the BOOT XSUB.
105  *
106  * See XSUB.h in core!
107  */
108 
109 
110 /* TODO: This might be compatible further back than 5.10.0. */
111 #if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
112 #  undef XS_EXTERNAL
113 #  undef XS_INTERNAL
114 #  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
115 #    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
116 #    define XS_INTERNAL(name) STATIC XSPROTO(name)
117 #  endif
118 #  if defined(__SYMBIAN32__)
119 #    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
120 #    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
121 #  endif
122 #  ifndef XS_EXTERNAL
123 #    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
124 #      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
125 #      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
126 #    else
127 #      ifdef __cplusplus
128 #        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
129 #        define XS_INTERNAL(name) static XSPROTO(name)
130 #      else
131 #        define XS_EXTERNAL(name) XSPROTO(name)
132 #        define XS_INTERNAL(name) STATIC XSPROTO(name)
133 #      endif
134 #    endif
135 #  endif
136 #endif
137 
138 /* perl >= 5.10.0 && perl <= 5.15.1 */
139 
140 
141 /* The XS_EXTERNAL macro is used for functions that must not be static
142  * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
143  * macro defined, the best we can do is assume XS is the same.
144  * Dito for XS_INTERNAL.
145  */
146 #ifndef XS_EXTERNAL
147 #  define XS_EXTERNAL(name) XS(name)
148 #endif
149 #ifndef XS_INTERNAL
150 #  define XS_INTERNAL(name) XS(name)
151 #endif
152 
153 /* Now, finally, after all this mess, we want an ExtUtils::ParseXS
154  * internal macro that we're free to redefine for varying linkage due
155  * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
156  * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
157  */
158 
159 #undef XS_EUPXS
160 #if defined(PERL_EUPXS_ALWAYS_EXPORT)
161 #  define XS_EUPXS(name) XS_EXTERNAL(name)
162 #else
163    /* default to internal */
164 #  define XS_EUPXS(name) XS_INTERNAL(name)
165 #endif
166 
167 #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
168 #define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)
169 
170 /* prototype to pass -Wmissing-prototypes */
171 STATIC void
172 S_croak_xs_usage(const CV *const cv, const char *const params);
173 
174 STATIC void
175 S_croak_xs_usage(const CV *const cv, const char *const params)
176 {
177     const GV *const gv = CvGV(cv);
178 
179     PERL_ARGS_ASSERT_CROAK_XS_USAGE;
180 
181     if (gv) {
182         const char *const gvname = GvNAME(gv);
183         const HV *const stash = GvSTASH(gv);
184         const char *const hvname = stash ? HvNAME(stash) : NULL;
185 
186         if (hvname)
187 	    Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
188         else
189 	    Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
190     } else {
191         /* Pants. I don't think that it should be possible to get here. */
192 	Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
193     }
194 }
195 #undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE
196 
197 #define croak_xs_usage        S_croak_xs_usage
198 
199 #endif
200 
201 /* NOTE: the prototype of newXSproto() is different in versions of perls,
202  * so we define a portable version of newXSproto()
203  */
204 #ifdef newXS_flags
205 #define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
206 #else
207 #define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
208 #endif /* !defined(newXS_flags) */
209 
210 #if PERL_VERSION_LE(5, 21, 5)
211 #  define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
212 #else
213 #  define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
214 #endif
215 
216 #line 217 "Intrs.c"
217 
218 XS_EUPXS(XS_Sun__Solaris__Intrs_intrmove); /* prototype to pass -Wmissing-prototypes */
219 XS_EUPXS(XS_Sun__Solaris__Intrs_intrmove)
220 {
221     dVAR; dXSARGS;
222     if (items != 5)
223        croak_xs_usage(cv,  "path, oldcpu, ino, cpu, num_ino");
224     {
225 	char *	path = (char *)SvPV_nolen(ST(0))
226 ;
227 	int	oldcpu = (int)SvIV(ST(1))
228 ;
229 	int	ino = (int)SvIV(ST(2))
230 ;
231 	int	cpu = (int)SvIV(ST(3))
232 ;
233 	int	num_ino = (int)SvIV(ST(4))
234 ;
235 	int	RETVAL;
236 	dXSTARG;
237 #line 74 "Intrs.xs"
238 	int fd, ret;
239 	pcitool_intr_set_t iset;
240 
241 #line 242 "Intrs.c"
242 #line 78 "Intrs.xs"
243 	if ((fd = open_dev(path)) == -1) {
244 		XSRETURN_UNDEF;
245 	}
246 	iset.old_cpu = oldcpu;
247 	iset.ino = ino;
248 	iset.cpu_id = cpu;
249 	iset.flags = (num_ino > 1) ? PCITOOL_INTR_FLAG_SET_GROUP : 0;
250 	iset.user_version = PCITOOL_VERSION;
251 
252 	ret = ioctl(fd, PCITOOL_DEVICE_SET_INTR, &iset);
253 
254 	if (ret == -1) {
255 		XSRETURN_UNDEF;
256 	}
257 	(void) close(fd);
258 	XSRETURN_YES;
259 #line 260 "Intrs.c"
260     }
261     XSRETURN(1);
262 }
263 
264 
265 XS_EUPXS(XS_Sun__Solaris__Intrs_is_apic); /* prototype to pass -Wmissing-prototypes */
266 XS_EUPXS(XS_Sun__Solaris__Intrs_is_apic)
267 {
268     dVAR; dXSARGS;
269     if (items != 1)
270        croak_xs_usage(cv,  "path");
271     {
272 	char *	path = (char *)SvPV_nolen(ST(0))
273 ;
274 	int	RETVAL;
275 	dXSTARG;
276 #line 100 "Intrs.xs"
277 	int fd, ret;
278 	pcitool_intr_info_t iinfo;
279 
280 #line 281 "Intrs.c"
281 #line 104 "Intrs.xs"
282 	if ((fd = open_dev(path)) == -1) {
283 		XSRETURN_UNDEF;
284 	}
285 	iinfo.user_version = PCITOOL_VERSION;
286 
287 	ret = ioctl(fd, PCITOOL_SYSTEM_INTR_INFO, &iinfo);
288 	(void) close(fd);
289 
290 	if (ret == -1) {
291 		XSRETURN_UNDEF;
292 	}
293 
294 	if (iinfo.ctlr_type == PCITOOL_CTLR_TYPE_PCPLUSMP ||
295 	    iinfo.ctlr_type == PCITOOL_CTLR_TYPE_APIX) {
296 		XSRETURN_YES;
297 	}
298 
299 	XSRETURN_NO;
300 #line 301 "Intrs.c"
301     }
302     XSRETURN(1);
303 }
304 
305 #ifdef __cplusplus
306 extern "C"
307 #endif
308 XS_EXTERNAL(boot_Sun__Solaris__Intrs); /* prototype to pass -Wmissing-prototypes */
309 XS_EXTERNAL(boot_Sun__Solaris__Intrs)
310 {
311 #if PERL_VERSION_LE(5, 21, 5)
312     dVAR; dXSARGS;
313 #else
314     dVAR; dXSBOOTARGSXSAPIVERCHK;
315 #endif
316 #if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
317     char* file = __FILE__;
318 #else
319     const char* file = __FILE__;
320 #endif
321 
322     PERL_UNUSED_VAR(file);
323 
324     PERL_UNUSED_VAR(cv); /* -W */
325     PERL_UNUSED_VAR(items); /* -W */
326 #if PERL_VERSION_LE(5, 21, 5)
327     XS_VERSION_BOOTCHECK;
328 #  ifdef XS_APIVERSION_BOOTCHECK
329     XS_APIVERSION_BOOTCHECK;
330 #  endif
331 #endif
332 
333         (void)newXSproto_portable("Sun::Solaris::Intrs::intrmove", XS_Sun__Solaris__Intrs_intrmove, file, "$$$$$");
334         (void)newXSproto_portable("Sun::Solaris::Intrs::is_apic", XS_Sun__Solaris__Intrs_is_apic, file, "$");
335 #if PERL_VERSION_LE(5, 21, 5)
336 #  if PERL_VERSION_GE(5, 9, 0)
337     if (PL_unitcheckav)
338         call_list(PL_scopestack_ix, PL_unitcheckav);
339 #  endif
340     XSRETURN_YES;
341 #else
342     Perl_xs_boot_epilog(aTHX_ ax);
343 #endif
344 }
345 
346