1Binary files pciutils-3.1.7.orig/.DS_Store and pciutils-3.1.7/.DS_Store differ
2diff -rupN pciutils-3.1.7.orig/lib/Makefile pciutils-3.1.7/lib/Makefile
3--- pciutils-3.1.7.orig/lib/Makefile	2009-07-04 09:11:04.000000000 -0700
4+++ pciutils-3.1.7/lib/Makefile	2011-02-10 15:40:40.000000000 -0800
5@@ -42,6 +42,10 @@ ifdef PCI_HAVE_PM_NBSD_LIBPCI
6 OBJS += nbsd-libpci
7 endif
8
9+ifdef PCI_HAVE_PM_DARWIN_DEVICE
10+OBJS += darwin-device
11+endif
12+
13 all: $(PCILIB) $(PCILIBPC)
14
15 ifeq ($(SHARED),no)
16diff -rupN pciutils-3.1.7.orig/lib/configure pciutils-3.1.7/lib/configure
17--- pciutils-3.1.7.orig/lib/configure	2009-07-04 09:11:04.000000000 -0700
18+++ pciutils-3.1.7/lib/configure	2011-02-10 16:18:46.000000000 -0800
19@@ -100,6 +100,14 @@ case $sys in
20 		echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
21 		LIBRESOLV=
22 		;;
23+
24+        darwin)
25+	        echo_n " darwin-device"
26+		echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE'
27+		echo >>$m 'WITH_LIBS+=-framework CoreFoundation -framework IOKit'
28+		echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
29+		LIBRESOLV=
30+		;;
31 	aix)
32 		echo_n " aix-device"
33 		echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
34diff -rupN pciutils-3.1.7.orig/lib/darwin-device.c pciutils-3.1.7/lib/darwin-device.c
35--- pciutils-3.1.7.orig/lib/darwin-device.c	1969-12-31 16:00:00.000000000 -0800
36+++ pciutils-3.1.7/lib/darwin-device.c	2011-02-11 10:45:06.000000000 -0800
37@@ -0,0 +1,226 @@
38+/*
39+ *	The PCI Library -- FreeBSD /dev/pci access
40+ *
41+ *	Copyright (c) 1999 Jari Kirma <kirma@cs.hut.fi>
42+ *	Updated in 2003 by Samy Al Bahra <samy@kerneled.com>
43+ *
44+ *	Can be freely distributed and used under the terms of the GNU GPL.
45+ */
46+
47+#include <errno.h>
48+#include <fcntl.h>
49+#include <stdio.h>
50+#include <string.h>
51+#include <unistd.h>
52+#include <stdint.h>
53+
54+#include "internal.h"
55+
56+
57+#include <CoreFoundation/CoreFoundation.h>
58+#include <IOKit/IOKitLib.h>
59+#include <IOKit/IOKitKeys.h>
60+
61+
62+enum {
63+	kACPIMethodAddressSpaceRead		= 0,
64+	kACPIMethodAddressSpaceWrite	= 1,
65+	kACPIMethodDebuggerCommand		= 2,
66+	kACPIMethodCount
67+};
68+
69+#pragma pack(1)
70+
71+typedef UInt32 IOACPIAddressSpaceID;
72+
73+enum {
74+    kIOACPIAddressSpaceIDSystemMemory       = 0,
75+    kIOACPIAddressSpaceIDSystemIO           = 1,
76+    kIOACPIAddressSpaceIDPCIConfiguration   = 2,
77+    kIOACPIAddressSpaceIDEmbeddedController = 3,
78+    kIOACPIAddressSpaceIDSMBus              = 4
79+};
80+
81+/*
82+ * 64-bit ACPI address
83+ */
84+union IOACPIAddress {
85+    UInt64 addr64;
86+    struct {
87+        unsigned int offset     :16;
88+        unsigned int function   :3;
89+        unsigned int device     :5;
90+        unsigned int bus        :8;
91+        unsigned int segment    :16;
92+        unsigned int reserved   :16;
93+    } pci;
94+};
95+typedef union IOACPIAddress IOACPIAddress;
96+
97+#pragma pack()
98+
99+struct AddressSpaceParam {
100+	UInt64			value;
101+	UInt32			spaceID;
102+	IOACPIAddress	address;
103+	UInt32			bitWidth;
104+	UInt32			bitOffset;
105+	UInt32			options;
106+};
107+typedef struct AddressSpaceParam AddressSpaceParam;
108+
109+
110+static void
111+darwin_config(struct pci_access *a UNUSED)
112+{
113+}
114+
115+static int
116+darwin_detect(struct pci_access *a)
117+{
118+	io_registry_entry_t    service;
119+	io_connect_t           connect;
120+	kern_return_t          status;
121+
122+	service = IOServiceGetMatchingService(kIOMasterPortDefault,
123+																					IOServiceMatching("AppleACPIPlatformExpert"));
124+	if (service)
125+	{
126+		status = IOServiceOpen(service, mach_task_self(), 0, &connect);
127+		IOObjectRelease(service);
128+	}
129+
130+  if (!service || (kIOReturnSuccess != status))
131+	{
132+		a->warning("Cannot open AppleACPIPlatformExpert (add boot arg debug=0x144 & run as root)");
133+		return 0;
134+	}
135+  a->debug("...using AppleACPIPlatformExpert");
136+  a->fd = connect;
137+  return 1;
138+}
139+
140+static void
141+darwin_init(struct pci_access *a UNUSED)
142+{
143+}
144+
145+static void
146+darwin_cleanup(struct pci_access *a UNUSED)
147+{
148+}
149+
150+static int
151+darwin_read(struct pci_dev *d, int pos, byte *buf, int len)
152+{
153+  if (!(len == 1 || len == 2 || len == 4))
154+    return pci_generic_block_read(d, pos, buf, len);
155+
156+  if (pos >= 256)
157+    return 0;
158+
159+	AddressSpaceParam param;
160+	kern_return_t     status;
161+
162+	param.spaceID   = kIOACPIAddressSpaceIDPCIConfiguration;
163+	param.bitWidth  = len * 8;
164+	param.bitOffset = 0;
165+	param.options   = 0;
166+
167+	param.address.pci.offset   = pos;
168+	param.address.pci.function = d->func;
169+	param.address.pci.device   = d->dev;
170+	param.address.pci.bus      = d->bus;
171+	param.address.pci.segment  = d->domain;
172+	param.address.pci.reserved = 0;
173+	param.value                = -1ULL;
174+
175+	size_t outSize = sizeof(param);
176+	status = IOConnectCallStructMethod(d->access->fd, kACPIMethodAddressSpaceRead,
177+																					&param, sizeof(param),
178+																					&param, &outSize);
179+  if ((kIOReturnSuccess != status))
180+	{
181+		d->access->error("darwin_read: kACPIMethodAddressSpaceRead failed: %s",
182+							mach_error_string(status));
183+	}
184+
185+  switch (len)
186+	{
187+    case 1:
188+      buf[0] = (u8) param.value;
189+      break;
190+    case 2:
191+      ((u16 *) buf)[0] = cpu_to_le16((u16) param.value);
192+      break;
193+    case 4:
194+      ((u32 *) buf)[0] = cpu_to_le32((u32) param.value);
195+      break;
196+	}
197+  return 1;
198+}
199+
200+static int
201+darwin_write(struct pci_dev *d, int pos, byte *buf, int len)
202+{
203+  if (!(len == 1 || len == 2 || len == 4))
204+    return pci_generic_block_write(d, pos, buf, len);
205+
206+  if (pos >= 256)
207+    return 0;
208+
209+	AddressSpaceParam param;
210+	kern_return_t     status;
211+
212+	param.spaceID   = kIOACPIAddressSpaceIDPCIConfiguration;
213+	param.bitWidth  = len * 8;
214+	param.bitOffset = 0;
215+	param.options   = 0;
216+
217+	param.address.pci.offset   = pos;
218+	param.address.pci.function = d->func;
219+	param.address.pci.device   = d->dev;
220+	param.address.pci.bus      = d->bus;
221+	param.address.pci.segment  = d->domain;
222+	param.address.pci.reserved = 0;
223+  switch (len)
224+	{
225+    case 1:
226+      param.value = buf[0];
227+      break;
228+    case 2:
229+      param.value = le16_to_cpu(((u16 *) buf)[0]);
230+      break;
231+    case 4:
232+      param.value = le32_to_cpu(((u32 *) buf)[0]);
233+      break;
234+	}
235+
236+	size_t outSize = 0;
237+	status = IOConnectCallStructMethod(d->access->fd, kACPIMethodAddressSpaceWrite,
238+																					&param, sizeof(param),
239+																					NULL, &outSize);
240+  if ((kIOReturnSuccess != status))
241+	{
242+		d->access->error("darwin_read: kACPIMethodAddressSpaceWrite failed: %s",
243+							mach_error_string(status));
244+	}
245+
246+  return 1;
247+}
248+
249+struct pci_methods pm_darwin_device = {
250+  "darwin-device",
251+  "Darwin device",
252+  darwin_config,
253+  darwin_detect,
254+  darwin_init,
255+  darwin_cleanup,
256+  pci_generic_scan,
257+  pci_generic_fill_info,
258+  darwin_read,
259+  darwin_write,
260+  NULL,                                 /* read_vpd */
261+  NULL,                                 /* dev_init */
262+  NULL                                  /* dev_cleanup */
263+};
264diff -rupN pciutils-3.1.7.orig/lib/init.c pciutils-3.1.7/lib/init.c
265--- pciutils-3.1.7.orig/lib/init.c	2008-11-10 15:11:51.000000000 -0800
266+++ pciutils-3.1.7/lib/init.c	2011-02-10 15:37:42.000000000 -0800
267@@ -57,6 +57,11 @@ static struct pci_methods *pci_methods[P
268 #else
269   NULL,
270 #endif
271+#ifdef PCI_HAVE_PM_DARWIN_DEVICE
272+  &pm_darwin_device,
273+#else
274+  NULL,
275+#endif
276 };
277
278 void *
279diff -rupN pciutils-3.1.7.orig/lib/internal.h pciutils-3.1.7/lib/internal.h
280--- pciutils-3.1.7.orig/lib/internal.h	2009-07-04 09:11:04.000000000 -0700
281+++ pciutils-3.1.7/lib/internal.h	2011-02-10 15:38:37.000000000 -0800
282@@ -68,4 +68,4 @@ void pci_free_caps(struct pci_dev *);
283
284 extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc,
285 	pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device,
286-	pm_dump, pm_linux_sysfs;
287+	pm_dump, pm_linux_sysfs, pm_darwin_device;
288diff -rupN pciutils-3.1.7.orig/lib/pci.h pciutils-3.1.7/lib/pci.h
289--- pciutils-3.1.7.orig/lib/pci.h	2009-07-04 09:11:04.000000000 -0700
290+++ pciutils-3.1.7/lib/pci.h	2011-02-10 16:15:58.000000000 -0800
291@@ -39,7 +39,8 @@ enum pci_access_type {
292   PCI_ACCESS_AIX_DEVICE,		/* /dev/pci0, /dev/bus0, etc. */
293   PCI_ACCESS_NBSD_LIBPCI,		/* NetBSD libpci */
294   PCI_ACCESS_OBSD_DEVICE,		/* OpenBSD /dev/pci */
295-  PCI_ACCESS_DUMP,			/* Dump file */
296+  PCI_ACCESS_DUMP,			    /* Dump file */
297+  PCI_ACCESS_DARWIN,			/* Darwin */
298   PCI_ACCESS_MAX
299 };
300
301