xref: /illumos-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Intrs/Intrs.xs (revision 2aeafac3612e19716bf8164f89c3c9196342979c)
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 #include "perl.h"
40 #include "XSUB.h"
41 
42 static int
43 open_dev(char *path)
44 {
45 	char intrpath[MAXPATHLEN];
46 
47 	(void) strcpy(intrpath, "/devices");
48 	(void) strcat(intrpath, path);
49 	(void) strcat(intrpath, ":intr");
50 	return (open(intrpath, O_RDWR));
51 }
52 
53 MODULE = Sun::Solaris::Intrs		PACKAGE = Sun::Solaris::Intrs
54 PROTOTYPES: ENABLE
55 
56 int
57 intrmove(path, oldcpu, ino, cpu, num_ino)
58 	char *path
59 	int oldcpu
60 	int ino
61 	int cpu
62 	int num_ino
63     INIT:
64 	int fd, ret;
65 	pcitool_intr_set_t iset;
66 
67     CODE:
68 	if ((fd = open_dev(path)) == -1) {
69 		XSRETURN_UNDEF;
70 	}
71 	iset.old_cpu = oldcpu;
72 	iset.ino = ino;
73 	iset.cpu_id = cpu;
74 	iset.flags = (num_ino > 1) ? PCITOOL_INTR_FLAG_SET_GROUP : 0;
75 	iset.user_version = PCITOOL_VERSION;
76 
77 	ret = ioctl(fd, PCITOOL_DEVICE_SET_INTR, &iset);
78 
79 	if (ret == -1) {
80 		XSRETURN_UNDEF;
81 	}
82 	(void) close(fd);
83 	XSRETURN_YES;
84 
85 int
86 is_apic(path)
87 	char *path
88 
89     INIT:
90 	int fd, ret;
91 	pcitool_intr_info_t iinfo;
92 
93     CODE:
94 	if ((fd = open_dev(path)) == -1) {
95 		XSRETURN_UNDEF;
96 	}
97 	iinfo.user_version = PCITOOL_VERSION;
98 
99 	ret = ioctl(fd, PCITOOL_SYSTEM_INTR_INFO, &iinfo);
100 	(void) close(fd);
101 
102 	if (ret == -1) {
103 		XSRETURN_UNDEF;
104 	}
105 
106 	if (iinfo.ctlr_type == PCITOOL_CTLR_TYPE_PCPLUSMP ||
107 	    iinfo.ctlr_type == PCITOOL_CTLR_TYPE_APIX) {
108 		XSRETURN_YES;
109 	}
110 
111 	XSRETURN_NO;
112