2 Copyright © 2003-2009, The AROS Development Team.
6 #include <exec/types.h>
7 #include <exec/memory.h>
8 #include <libraries/mui.h>
11 #include <utility/tagitem.h>
12 #include <utility/hooks.h>
14 #include <proto/exec.h>
15 #include <proto/muimaster.h>
16 #include <proto/oop.h>
17 #include <proto/utility.h>
18 #include <proto/intuition.h>
21 #include <aros/debug.h>
28 #define APPNAME "PCITool"
29 #define VERSION "PCITool 0.2 (20.4.2009)"
31 static const char version
[] = "$VER: " VERSION
"\n";
33 struct Library
*OOPBase
= NULL
;
34 struct Library
*MUIMasterBase
= NULL
;
35 struct UtilityBase
*UtilityBase
= NULL
;
37 OOP_AttrBase __IHidd_PCIDev
;
38 OOP_AttrBase __IHidd_PCIDrv
;
39 OOP_AttrBase HiddAttrBase
;
45 if ((OOPBase
=OpenLibrary("oop.library", 0)) != NULL
)
47 __IHidd_PCIDev
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
48 __IHidd_PCIDrv
= OOP_ObtainAttrBase(IID_Hidd_PCIDriver
);
49 HiddAttrBase
= OOP_ObtainAttrBase(IID_Hidd
);
51 if ((MUIMasterBase
=OpenLibrary("muimaster.library", 0)) != NULL
)
53 if ((UtilityBase
=(struct UtilityBase
*)OpenLibrary("utility.library", 0)) != NULL
)
68 OOP_DisposeObject(pci
);
70 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice
);
71 OOP_ReleaseAttrBase(IID_Hidd_PCIDriver
);
72 OOP_ReleaseAttrBase(IID_Hidd
);
75 CloseLibrary(OOPBase
);
77 if (UtilityBase
!= NULL
)
78 CloseLibrary((struct Library
*)UtilityBase
);
80 if (MUIMasterBase
!= NULL
)
81 CloseLibrary(MUIMasterBase
);
88 void cleanup(CONST_STRPTR message
)
90 Locale_Deinitialize();
94 ShowError(NULL
, NULL
, message
, TRUE
);
103 Object
*MakeLabel(STRPTR str
)
105 return (MUI_MakeObject(MUIO_Label
, str
, 0));
108 LONG
xget(Object
* obj
, ULONG attr
)
118 Object
*StrDriverName
, *StrDriverHWName
, *StrDriverDirect
;
120 Object
*StrDescription
, *VendorID
, *ProductID
, *RevisionID
;
121 Object
*VendorName
, *ProductName
, *SubsystemName
;
122 Object
*Interface
, *_Class
, *SubClass
, *IRQLine
;
123 Object
*ROMBase
, *ROMSize
;
127 struct Hook pci_hook
;
128 struct Hook display_hook
;
129 struct Hook select_hook
;
131 AROS_UFH3(void, pci_callback
,
132 AROS_UFHA(struct Hook
*, hook
, A0
),
133 AROS_UFHA(OOP_Object
*, obj
, A2
),
134 AROS_UFHA(APTR
, msg
, A1
))
138 DoMethod(DriverList
, MUIM_List_InsertSingle
, (IPTR
)obj
, MUIV_List_Insert_Bottom
);
143 AROS_UFH3(void, display_function
,
144 AROS_UFHA(struct Hook
*, h
, A0
),
145 AROS_UFHA(char **, strings
, A2
),
146 AROS_UFHA(OOP_Object
*, obj
, A1
))
155 OOP_GetAttr(obj
, aHidd_PCIDevice_Bus
, (APTR
)&bus
);
156 OOP_GetAttr(obj
, aHidd_PCIDevice_Dev
, (APTR
)&dev
);
157 OOP_GetAttr(obj
, aHidd_PCIDevice_Sub
, (APTR
)&sub
);
159 snprintf(buf
, 19, "%02x.%02x.%01x", bus
, dev
, sub
);
166 void memoryPrint(STRPTR buffer
, unsigned int bar
, unsigned int base
, unsigned int size
, unsigned int type
)
170 snprintf(buffer
, 59, "Bar%d: %s%s at 0x%04x (size 0x%04x)", bar
,
171 (type
& ADDRF_PREFETCH
) ? "Prefetchable " :"",
172 (type
& ADDRF_IO
)?"I/O":"Memory",
177 snprintf(buffer
, 59, "Bar%d: %s%s at 0x%08x (size 0x%08x)", bar
,
178 (type
& ADDRF_PREFETCH
) ? "Prefetchable " :"",
179 (type
& ADDRF_IO
)?"I/O":"Memory",
184 AROS_UFH3(void, select_function
,
185 AROS_UFHA(struct Hook
*, h
, A0
),
186 AROS_UFHA(Object
*, object
, A2
),
187 AROS_UFHA(APTR
, msg
, A1
))
192 OOP_Object
*obj
, *drv
;
193 STRPTR
class, subclass
, interface
, str
;
194 UWORD vendor
, product
, subvendor
, subdevice
;
196 active
= xget(object
, MUIA_List_Active
);
197 if (active
!= MUIV_List_Active_Off
)
199 IPTR val
, val2
, val3
;
202 static char ranges
[6][60];
203 DoMethod(object
, MUIM_List_GetEntry
, active
, (IPTR
)&obj
);
205 OOP_GetAttr(obj
, aHidd_PCIDevice_Driver
, (APTR
)&drv
);
206 OOP_GetAttr(drv
, aHidd_Name
, (APTR
)&str
);
207 set(StrDriverName
, MUIA_Text_Contents
, str
);
208 OOP_GetAttr(drv
, aHidd_HardwareName
, (APTR
)&str
);
209 set(StrDriverHWName
, MUIA_Text_Contents
, str
);
210 OOP_GetAttr(drv
, aHidd_PCIDriver_DirectBus
, (APTR
)&val
);
211 set(StrDriverDirect
, MUIA_Text_Contents
, (IPTR
)((val
)?_(MSG_YES
):_(MSG_NO
)));
213 OOP_GetAttr(obj
, aHidd_PCIDevice_ClassDesc
, (APTR
)&class);
214 OOP_GetAttr(obj
, aHidd_PCIDevice_SubClassDesc
, (APTR
)&subclass
);
215 OOP_GetAttr(obj
, aHidd_PCIDevice_InterfaceDesc
, (APTR
)&interface
);
216 snprintf(buf
, 79, "%s %s %s", class, subclass
, interface
);
217 set(StrDescription
, MUIA_Text_Contents
, buf
);
219 OOP_GetAttr(obj
, aHidd_PCIDevice_VendorID
, (APTR
)&val
);
220 snprintf(buf
, 79, "0x%04x", val
);
221 set(VendorID
, MUIA_Text_Contents
, buf
);
222 set(VendorName
, MUIA_Text_Contents
, pciids_GetVendorName(val
, buf
, 79));
225 OOP_GetAttr(obj
, aHidd_PCIDevice_ProductID
, (APTR
)&val
);
226 snprintf(buf
, 79, "0x%04x", val
);
227 set(ProductID
, MUIA_Text_Contents
, buf
);
228 set(ProductName
, MUIA_Text_Contents
,
229 pciids_GetDeviceName(vendor
, val
, buf
, 79));
232 OOP_GetAttr(obj
, aHidd_PCIDevice_SubsystemVendorID
, (APTR
)&val
);
234 OOP_GetAttr(obj
, aHidd_PCIDevice_SubsystemID
, (APTR
)&val
);
236 set(SubsystemName
, MUIA_Text_Contents
,
237 pciids_GetSubDeviceName(vendor
, product
, subvendor
, subdevice
,
240 OOP_GetAttr(obj
, aHidd_PCIDevice_RevisionID
, (APTR
)&val
);
241 snprintf(buf
, 79, "0x%04x", val
);
242 set(RevisionID
, MUIA_Text_Contents
, buf
);
244 OOP_GetAttr(obj
, aHidd_PCIDevice_Interface
, (APTR
)&val
);
245 snprintf(buf
, 79, "0x%02x", val
);
246 set(Interface
, MUIA_Text_Contents
, buf
);
248 OOP_GetAttr(obj
, aHidd_PCIDevice_Class
, (APTR
)&val
);
249 snprintf(buf
, 79, "0x%02x", val
);
250 set(_Class
, MUIA_Text_Contents
, buf
);
252 OOP_GetAttr(obj
, aHidd_PCIDevice_SubClass
, (APTR
)&val
);
253 snprintf(buf
, 79, "0x%02x", val
);
254 set(SubClass
, MUIA_Text_Contents
, buf
);
256 OOP_GetAttr(obj
, aHidd_PCIDevice_IRQLine
, (APTR
)&val
);
257 OOP_GetAttr(obj
, aHidd_PCIDevice_INTLine
, (APTR
)&val2
);
260 snprintf(buf
, 79, "%d (%c)", val2
, val
+ 'A' - 1);
262 else snprintf(buf
, 79, _(MSG_NA
));
263 set(IRQLine
, MUIA_Text_Contents
, buf
);
265 OOP_GetAttr(obj
, aHidd_PCIDevice_RomBase
, (APTR
)&val
);
266 OOP_GetAttr(obj
, aHidd_PCIDevice_RomSize
, (APTR
)&val2
);
267 snprintf(buf
, 79, "0x%08x", val2
);
270 set(ROMSize
, MUIA_Text_Contents
, buf
);
273 snprintf(buf
, 79, "0x%08x", val
);
274 set(ROMBase
, MUIA_Text_Contents
, buf
);
276 else set(ROMBase
, MUIA_Text_Contents
, _(MSG_UNUSED
));
280 set(ROMBase
, MUIA_Text_Contents
, _(MSG_NA
));
281 set(ROMSize
, MUIA_Text_Contents
, _(MSG_NA
));
284 DoMethod(RangeList
, MUIM_List_Clear
);
286 OOP_GetAttr(obj
, aHidd_PCIDevice_Base0
, (APTR
)&val
);
287 OOP_GetAttr(obj
, aHidd_PCIDevice_Size0
, (APTR
)&val2
);
288 OOP_GetAttr(obj
, aHidd_PCIDevice_Type0
, (APTR
)&val3
);
292 memoryPrint(ranges
[0], 0, val
, val2
, val3
);
293 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[0], MUIV_List_Insert_Bottom
);
296 OOP_GetAttr(obj
, aHidd_PCIDevice_Base1
, (APTR
)&val
);
297 OOP_GetAttr(obj
, aHidd_PCIDevice_Size1
, (APTR
)&val2
);
298 OOP_GetAttr(obj
, aHidd_PCIDevice_Type1
, (APTR
)&val3
);
302 memoryPrint(ranges
[1], 1, val
, val2
, val3
);
303 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[1], MUIV_List_Insert_Bottom
);
306 OOP_GetAttr(obj
, aHidd_PCIDevice_isBridge
, (APTR
)&val
);
310 OOP_GetAttr(obj
, aHidd_PCIDevice_Base2
, (APTR
)&val
);
311 OOP_GetAttr(obj
, aHidd_PCIDevice_Size2
, (APTR
)&val2
);
312 OOP_GetAttr(obj
, aHidd_PCIDevice_Type2
, (APTR
)&val3
);
316 memoryPrint(ranges
[2], 2, val
, val2
, val3
);
317 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[2], MUIV_List_Insert_Bottom
);
320 OOP_GetAttr(obj
, aHidd_PCIDevice_Base3
, (APTR
)&val
);
321 OOP_GetAttr(obj
, aHidd_PCIDevice_Size3
, (APTR
)&val2
);
322 OOP_GetAttr(obj
, aHidd_PCIDevice_Type3
, (APTR
)&val3
);
326 memoryPrint(ranges
[3], 3, val
, val2
, val3
);
327 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[3], MUIV_List_Insert_Bottom
);
330 OOP_GetAttr(obj
, aHidd_PCIDevice_Base4
, (APTR
)&val
);
331 OOP_GetAttr(obj
, aHidd_PCIDevice_Size4
, (APTR
)&val2
);
332 OOP_GetAttr(obj
, aHidd_PCIDevice_Type4
, (APTR
)&val3
);
336 memoryPrint(ranges
[4], 4, val
, val2
, val3
);
337 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[4], MUIV_List_Insert_Bottom
);
340 OOP_GetAttr(obj
, aHidd_PCIDevice_Base5
, (APTR
)&val
);
341 OOP_GetAttr(obj
, aHidd_PCIDevice_Size5
, (APTR
)&val2
);
342 OOP_GetAttr(obj
, aHidd_PCIDevice_Type5
, (APTR
)&val3
);
346 memoryPrint(ranges
[5], 5, val
, val2
, val3
);
347 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[5], MUIV_List_Insert_Bottom
);
352 OOP_GetAttr(obj
, aHidd_PCIDevice_SubBus
, (APTR
)&val
);
353 OOP_GetAttr(obj
, aHidd_PCIDevice_ISAEnable
, (APTR
)&val2
);
354 OOP_GetAttr(obj
, aHidd_PCIDevice_VGAEnable
, (APTR
)&val3
);
356 snprintf(ranges
[2], 59, _(MSG_BRIDGE
),
357 val
, (val2
) ? (CONST_STRPTR
)" " : _(MSG_NOT
),
358 (val3
) ? (CONST_STRPTR
)" " : _(MSG_NOT
));
359 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[2], MUIV_List_Insert_Bottom
);
361 OOP_GetAttr(obj
, aHidd_PCIDevice_MemoryBase
, (APTR
)&val
);
362 OOP_GetAttr(obj
, aHidd_PCIDevice_MemoryLimit
, (APTR
)&val2
);
364 snprintf(ranges
[3], 59, _(MSG_MEMORY_RANGE
),
366 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[3], MUIV_List_Insert_Bottom
);
368 OOP_GetAttr(obj
, aHidd_PCIDevice_PrefetchableBase
, (APTR
)&val
);
369 OOP_GetAttr(obj
, aHidd_PCIDevice_PrefetchableLimit
, (APTR
)&val2
);
371 snprintf(ranges
[4], 59, _(MSG_PREFETCHABLE_MEMORY
),
373 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[4], MUIV_List_Insert_Bottom
);
375 OOP_GetAttr(obj
, aHidd_PCIDevice_IOBase
, (APTR
)&val
);
376 OOP_GetAttr(obj
, aHidd_PCIDevice_IOLimit
, (APTR
)&val2
);
378 snprintf(ranges
[5], 59, _(MSG_IO_RANGE
),
380 DoMethod(RangeList
, MUIM_List_InsertSingle
, (IPTR
)ranges
[5], MUIV_List_Insert_Bottom
);
384 IPTR io
, mem
, master
, snoop
, is66
;
385 OOP_GetAttr(obj
, aHidd_PCIDevice_isIO
, (APTR
)&io
);
386 OOP_GetAttr(obj
, aHidd_PCIDevice_isMEM
, (APTR
)&mem
);
387 OOP_GetAttr(obj
, aHidd_PCIDevice_isMaster
, (APTR
)&master
);
388 OOP_GetAttr(obj
, aHidd_PCIDevice_paletteSnoop
, (APTR
)&snoop
);
389 OOP_GetAttr(obj
, aHidd_PCIDevice_is66MHz
, (APTR
)&is66
);
391 snprintf(buf
, 79, _(MSG_IO_MSG
),
392 io
? _(MSG_YES
):_(MSG_NO
),
393 mem
? _(MSG_YES
):_(MSG_NO
),
394 master
? _(MSG_YES
):_(MSG_NO
),
395 snoop
? _(MSG_YES
):_(MSG_NO
),
396 is66
? _(MSG_YES
):_(MSG_NO
));
397 set(Status
, MUIA_Text_Contents
, buf
);
408 app
= ApplicationObject
,
409 MUIA_Application_Title
, (IPTR
)APPNAME
,
410 MUIA_Application_Version
, (IPTR
)VERSION
,
411 MUIA_Application_Copyright
, (IPTR
)"© 2004, The AROS Development Team",
412 MUIA_Application_Author
, (IPTR
)"Michal Schulz",
413 MUIA_Application_Base
, (IPTR
)APPNAME
,
414 MUIA_Application_Description
, __(MSG_DESCRIPTION
),
416 SubWindow
, MainWindow
= WindowObject
,
417 MUIA_Window_Title
, __(MSG_WINTITLE
),
418 // MUIA_Window_Height, MUIV_Window_Height_Visible(50),
419 // MUIA_Window_Width, MUIV_Window_Width_Visible(60),
421 WindowContents
, HGroup
,
422 MUIA_Group_SameWidth
, FALSE
,
424 Child
, ListviewObject
,
425 MUIA_Listview_List
, DriverList
= ListObject
,
427 MUIA_List_AdjustWidth
, TRUE
,
428 MUIA_List_DisplayHook
, &display_hook
,
432 Child
, VGroup
, GroupFrameT(_(MSG_DRIVER_INFO
)),
434 Child
, Label(_(MSG_DRIVER_NAME
)),
436 Child
, StrDriverName
= TextObject
,
438 MUIA_Background
, MUII_TextBack
,
439 MUIA_Text_SetMax
, FALSE
,
440 MUIA_Text_Contents
, "",
442 Child
, Label(_(MSG_DIRECT_BUS
)),
443 Child
, StrDriverDirect
= TextObject
,
445 MUIA_Background
, MUII_TextBack
,
446 MUIA_Text_SetMax
, FALSE
,
447 MUIA_Text_Contents
, "",
450 Child
, Label(_(MSG_HARDWARE_INFO
)),
451 Child
, StrDriverHWName
= TextObject
,
453 MUIA_Background
, MUII_TextBack
,
454 MUIA_Text_SetMax
, FALSE
,
455 MUIA_Text_Contents
, "",
459 Child
, VGroup
, GroupFrameT(_(MSG_PCI_DEVICE_INFO
)),
461 Child
, Label(_(MSG_DEVICE_DESCRIPTION
)),
462 Child
, StrDescription
= TextObject
,
464 MUIA_Background
, MUII_TextBack
,
465 MUIA_Text_SetMax
, FALSE
,
466 MUIA_Text_Contents
, "",
468 Child
, Label(_(MSG_VENDORNAME
)),
469 Child
, VendorName
= TextObject
,
471 MUIA_Background
, MUII_TextBack
,
472 MUIA_Text_SetMax
, FALSE
,
473 MUIA_Text_Contents
, "",
475 Child
, Label(_(MSG_PRODUCTNAME
)),
476 Child
, ProductName
= TextObject
,
478 MUIA_Background
, MUII_TextBack
,
479 MUIA_Text_SetMax
, FALSE
,
480 MUIA_Text_Contents
, "",
482 Child
, Label(_(MSG_SUBSYSTEM
)),
483 Child
, SubsystemName
= TextObject
,
485 MUIA_Background
, MUII_TextBack
,
486 MUIA_Text_SetMax
, FALSE
,
487 MUIA_Text_Contents
, "",
492 Child
, Label(_(MSG_VENDORID
)),
493 Child
, VendorID
= TextObject
,
495 MUIA_Background
, MUII_TextBack
,
496 MUIA_Text_SetMax
, FALSE
,
497 MUIA_Text_Contents
, "0x0000",
501 Child
, Label(_(MSG_PRODUCTID
)),
502 Child
, ProductID
= TextObject
,
504 MUIA_Background
, MUII_TextBack
,
505 MUIA_Text_SetMax
, FALSE
,
506 MUIA_Text_Contents
, "0x0000",
510 Child
, Label(_(MSG_REVISIONID
)),
511 Child
, RevisionID
= TextObject
,
513 MUIA_Background
, MUII_TextBack
,
514 MUIA_Text_SetMax
, FALSE
,
515 MUIA_Text_Contents
, "0x0000",
522 Child
, Label(_(MSG_INTERFACE
)),
523 Child
, Interface
= TextObject
,
525 MUIA_Background
, MUII_TextBack
,
526 MUIA_Text_SetMax
, FALSE
,
527 MUIA_Text_Contents
, "0x00",
532 Child
, Label(_(MSG_CLASS
)),
533 Child
, _Class
= TextObject
,
535 MUIA_Background
, MUII_TextBack
,
536 MUIA_Text_SetMax
, FALSE
,
537 MUIA_Text_Contents
, "0x00",
542 Child
, Label(_(MSG_SUBCLASS
)),
543 Child
, SubClass
= TextObject
,
545 MUIA_Background
, MUII_TextBack
,
546 MUIA_Text_SetMax
, FALSE
,
547 MUIA_Text_Contents
, "0x00",
551 Child
, Label(_(MSG_IRQ
)),
552 Child
, IRQLine
= TextObject
,
554 MUIA_Background
, MUII_TextBack
,
555 MUIA_Text_SetMax
, FALSE
,
556 MUIA_Text_Contents
, "15",
563 Child
, Label(_(MSG_ROM_BASE
)),
564 Child
, ROMBase
= TextObject
,
566 MUIA_Background
, MUII_TextBack
,
567 MUIA_Text_SetMax
, FALSE
,
568 MUIA_Text_Contents
, "0x00000000",
573 Child
, Label(_(MSG_ROM_SIZE
)),
574 Child
, ROMSize
= TextObject
,
576 MUIA_Background
, MUII_TextBack
,
577 MUIA_Text_SetMax
, FALSE
,
578 MUIA_Text_Contents
, "0x00000000",
584 Child
, RangeList
= ListviewObject
,
585 MUIA_Listview_List
, ListObject
,
587 MUIA_List_AdjustWidth
, FALSE
,
591 Child
, Status
= TextObject
,
593 MUIA_Background
, MUII_TextBack
,
594 MUIA_Text_SetMax
, FALSE
,
598 End
, // WindowContents
600 End
; // ApplicationObject
604 /* Quit application if the windowclosegadget or the esc key is pressed. */
606 DoMethod(MainWindow
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
608 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
610 DoMethod(DriverList
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
,
612 MUIM_CallHook
, (IPTR
)&select_hook
);
623 while((LONG
) DoMethod(app
, MUIM_Application_NewInput
, (IPTR
)&sigs
) != MUIV_Application_ReturnID_Quit
)
633 int main(int argc
, char *argv
[])
635 pci_hook
.h_Entry
= (APTR
)pci_callback
;
636 display_hook
.h_Entry
= (APTR
)display_function
;
637 select_hook
.h_Entry
= (APTR
)select_function
;
639 if (!Locale_Initialize())
640 cleanup(_(MSG_ERROR_LOCALE
));
646 pci
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
649 HIDD_PCI_EnumDevices(pci
, &pci_hook
, NULL
);
652 set(MainWindow
, MUIA_Window_Open
, TRUE
);
654 if(xget(MainWindow
, MUIA_Window_Open
))
659 set(MainWindow
, MUIA_Window_Open
, FALSE
);
670 } /* main(int argc, char *argv[]) */