1bd335c64Sesolom /*
2bd335c64Sesolom  * CDDL HEADER START
3bd335c64Sesolom  *
4bd335c64Sesolom  * The contents of this file are subject to the terms of the
5cfe67ef2Salanbur  * Common Development and Distribution License (the "License").
6cfe67ef2Salanbur  * You may not use this file except in compliance with the License.
7bd335c64Sesolom  *
8bd335c64Sesolom  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9bd335c64Sesolom  * or http://www.opensolaris.org/os/licensing.
10bd335c64Sesolom  * See the License for the specific language governing permissions
11bd335c64Sesolom  * and limitations under the License.
12bd335c64Sesolom  *
13bd335c64Sesolom  * When distributing Covered Code, include this CDDL HEADER in each
14bd335c64Sesolom  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15bd335c64Sesolom  * If applicable, add the following below this CDDL HEADER, with the
16bd335c64Sesolom  * fields enclosed by brackets "[]" replaced with your own identifying
17bd335c64Sesolom  * information: Portions Copyright [yyyy] [name of copyright owner]
18bd335c64Sesolom  *
19bd335c64Sesolom  * CDDL HEADER END
20bd335c64Sesolom  */
21bd335c64Sesolom 
22bd335c64Sesolom /*
23e436569bSJohn Sonnenschein  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24bd335c64Sesolom  */
25bd335c64Sesolom 
26bd335c64Sesolom #include <sys/types.h>
27bd335c64Sesolom #include <sys/stat.h>
28bd335c64Sesolom #include <sys/pci.h>
29bd335c64Sesolom #include <fcntl.h>
30bd335c64Sesolom #include <unistd.h>
31bd335c64Sesolom #include <stropts.h>
32bd335c64Sesolom #include <stdio.h>
33bd335c64Sesolom #include <errno.h>
34bd335c64Sesolom 
35cfe67ef2Salanbur /* Non-shipping header - see Makefile.PL */
36e436569bSJohn Sonnenschein #include <sys/pci_tools.h>
37bd335c64Sesolom 
38bd335c64Sesolom #include "EXTERN.h"
39bd335c64Sesolom #include "perl.h"
40bd335c64Sesolom #include "XSUB.h"
41bd335c64Sesolom 
422917a9c9Sschwartz static int
open_dev(char * path)432917a9c9Sschwartz open_dev(char *path)
442917a9c9Sschwartz {
452917a9c9Sschwartz 	char intrpath[MAXPATHLEN];
462917a9c9Sschwartz 
472917a9c9Sschwartz 	(void) strcpy(intrpath, "/devices");
482917a9c9Sschwartz 	(void) strcat(intrpath, path);
492917a9c9Sschwartz 	(void) strcat(intrpath, ":intr");
502917a9c9Sschwartz 	return (open(intrpath, O_RDWR));
512917a9c9Sschwartz }
522917a9c9Sschwartz 
53bd335c64Sesolom MODULE = Sun::Solaris::Intrs		PACKAGE = Sun::Solaris::Intrs
54bd335c64Sesolom PROTOTYPES: ENABLE
55bd335c64Sesolom 
56bd335c64Sesolom int
intrmove(path,oldcpu,ino,cpu,num_ino)57*7ff178cdSJimmy Vetayases intrmove(path, oldcpu, ino, cpu, num_ino)
58bd335c64Sesolom 	char *path
59*7ff178cdSJimmy Vetayases 	int oldcpu
60bd335c64Sesolom 	int ino
61bd335c64Sesolom 	int cpu
622917a9c9Sschwartz 	int num_ino
63bd335c64Sesolom     INIT:
642917a9c9Sschwartz 	int fd, ret;
65bd335c64Sesolom 	pcitool_intr_set_t iset;
66bd335c64Sesolom 
67bd335c64Sesolom     CODE:
682917a9c9Sschwartz 	if ((fd = open_dev(path)) == -1) {
692917a9c9Sschwartz 		XSRETURN_UNDEF;
70bd335c64Sesolom 	}
71*7ff178cdSJimmy Vetayases 	iset.old_cpu = oldcpu;
72bd335c64Sesolom 	iset.ino = ino;
73bd335c64Sesolom 	iset.cpu_id = cpu;
7409b1eac2SEvan Yan 	iset.flags = (num_ino > 1) ? PCITOOL_INTR_FLAG_SET_GROUP : 0;
752917a9c9Sschwartz 	iset.user_version = PCITOOL_VERSION;
76bd335c64Sesolom 
77bd335c64Sesolom 	ret = ioctl(fd, PCITOOL_DEVICE_SET_INTR, &iset);
78bd335c64Sesolom 
79bd335c64Sesolom 	if (ret == -1) {
80bd335c64Sesolom 		XSRETURN_UNDEF;
81bd335c64Sesolom 	}
822917a9c9Sschwartz 	(void) close(fd);
83bd335c64Sesolom 	XSRETURN_YES;
842917a9c9Sschwartz 
852917a9c9Sschwartz int
86*7ff178cdSJimmy Vetayases is_apic(path)
872917a9c9Sschwartz 	char *path
882917a9c9Sschwartz 
892917a9c9Sschwartz     INIT:
902917a9c9Sschwartz 	int fd, ret;
912917a9c9Sschwartz 	pcitool_intr_info_t iinfo;
922917a9c9Sschwartz 
932917a9c9Sschwartz     CODE:
942917a9c9Sschwartz 	if ((fd = open_dev(path)) == -1) {
952917a9c9Sschwartz 		XSRETURN_UNDEF;
962917a9c9Sschwartz 	}
972917a9c9Sschwartz 	iinfo.user_version = PCITOOL_VERSION;
982917a9c9Sschwartz 
992917a9c9Sschwartz 	ret = ioctl(fd, PCITOOL_SYSTEM_INTR_INFO, &iinfo);
1002917a9c9Sschwartz 	(void) close(fd);
1012917a9c9Sschwartz 
1022917a9c9Sschwartz 	if (ret == -1) {
1032917a9c9Sschwartz 		XSRETURN_UNDEF;
1042917a9c9Sschwartz 	}
1052917a9c9Sschwartz 
106*7ff178cdSJimmy Vetayases 	if (iinfo.ctlr_type == PCITOOL_CTLR_TYPE_PCPLUSMP ||
107*7ff178cdSJimmy Vetayases 	    iinfo.ctlr_type == PCITOOL_CTLR_TYPE_APIX) {
1082917a9c9Sschwartz 		XSRETURN_YES;
1092917a9c9Sschwartz 	}
1102917a9c9Sschwartz 
1112917a9c9Sschwartz 	XSRETURN_NO;
112