1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <sys/pci.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31 #include <stropts.h>
32 #include <stdio.h>
33 #include <errno.h>
34
35 /* Non-shipping header - see Makefile.PL */
36 #include <sys/pci_tools.h>
37
38 #include "EXTERN.h"
39 #if __GNUC__ >= 5
40 #include "perl.h"
41 #else
42 #define _Thread_local
43 #include "perl.h"
44 #undef _Thread_local
45 #undef PERL_GET_CONTEXT
46 #undef PERL_SET_CONTEXT
47 #define PERL_GET_CONTEXT PTHREAD_GETSPECIFIC(PL_thr_key)
48 #define PERL_SET_CONTEXT(t) Perl_set_context((void*)t)
49 #endif
50 #include "XSUB.h"
51
52 static int
open_dev(char * path)53 open_dev(char *path)
54 {
55 char intrpath[MAXPATHLEN];
56
57 (void) strcpy(intrpath, "/devices");
58 (void) strcat(intrpath, path);
59 (void) strcat(intrpath, ":intr");
60 return (open(intrpath, O_RDWR));
61 }
62
63 MODULE = Sun::Solaris::Intrs PACKAGE = Sun::Solaris::Intrs
64 PROTOTYPES: ENABLE
65
66 int
intrmove(path,oldcpu,ino,cpu,num_ino)67 intrmove(path, oldcpu, ino, cpu, num_ino)
68 char *path
69 int oldcpu
70 int ino
71 int cpu
72 int num_ino
73 INIT:
74 int fd, ret;
75 pcitool_intr_set_t iset;
76
77 CODE:
78 if ((fd = open_dev(path)) == -1) {
79 XSRETURN_UNDEF;
80 }
81 iset.old_cpu = oldcpu;
82 iset.ino = ino;
83 iset.cpu_id = cpu;
84 iset.flags = (num_ino > 1) ? PCITOOL_INTR_FLAG_SET_GROUP : 0;
85 iset.user_version = PCITOOL_VERSION;
86
87 ret = ioctl(fd, PCITOOL_DEVICE_SET_INTR, &iset);
88
89 if (ret == -1) {
90 XSRETURN_UNDEF;
91 }
92 (void) close(fd);
93 XSRETURN_YES;
94
95 int
96 is_apic(path)
97 char *path
98
99 INIT:
100 int fd, ret;
101 pcitool_intr_info_t iinfo;
102
103 CODE:
104 if ((fd = open_dev(path)) == -1) {
105 XSRETURN_UNDEF;
106 }
107 iinfo.user_version = PCITOOL_VERSION;
108
109 ret = ioctl(fd, PCITOOL_SYSTEM_INTR_INFO, &iinfo);
110 (void) close(fd);
111
112 if (ret == -1) {
113 XSRETURN_UNDEF;
114 }
115
116 if (iinfo.ctlr_type == PCITOOL_CTLR_TYPE_PCPLUSMP ||
117 iinfo.ctlr_type == PCITOOL_CTLR_TYPE_APIX) {
118 XSRETURN_YES;
119 }
120
121 XSRETURN_NO;
122