1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
13 get-node CONSTANT my-phandle
15 \ get the PUID from the node above
16 s" my-puid" my-phandle parent $call-static CONSTANT my-puid
18 \ define the config reads
19 : config-b@ puid >r my-puid TO puid my-space + rtas-config-b@ r> TO puid ;
20 : config-w@ puid >r my-puid TO puid my-space + rtas-config-w@ r> TO puid ;
21 : config-l@ puid >r my-puid TO puid my-space + rtas-config-l@ r> TO puid ;
23 \ define the config writes
24 : config-b! puid >r my-puid TO puid my-space + rtas-config-b! r> TO puid ;
25 : config-w! puid >r my-puid TO puid my-space + rtas-config-w! r> TO puid ;
26 : config-l! puid >r my-puid TO puid my-space + rtas-config-l! r> TO puid ;
28 \ for Debug purposes: dumps the whole config space
29 : config-dump puid >r my-puid TO puid my-space pci-dump r> TO puid ;
31 \ prepare the device for subsequent use
32 \ this word should be overloaded by the device file (if present)
33 \ the device file can call this file before implementing
34 \ its own open functionality
36 puid >r \ save the old puid
37 my-puid TO puid \ set up the puid to the devices Hostbridge
38 pci-master-enable \ And enable Bus Master, IO and MEM access again.
39 pci-mem-enable \ enable mem access
40 pci-io-enable \ enable io access
41 r> TO puid \ restore puid
45 \ close the previously opened device
46 \ this word should be overloaded by the device file (if present)
47 \ the device file can call this file after its implementation
48 \ of own close functionality
50 puid >r \ save the old puid
51 my-puid TO puid \ set up the puid
52 pci-device-disable \ and disable the device
53 r> TO puid \ restore puid
56 s" dma-function.fs" included
58 \ generate the rom-fs filename from the vendor and device ID "pci-device_VENDORID_DEVICEID.fs"
59 : devicefile ( -- str len )
61 my-space pci-vendor@ 4 int2str $cat
63 my-space pci-device@ 4 int2str $cat
67 \ generate the rom-fs filename from the base-class id "pci-class_BASECLASS.fs"
68 : classfile ( -- str len )
70 my-space pci-class@ 10 rshift 2 int2str $cat
74 \ Set up the device with either default or special settings
76 \ is there special handling for this device, given vendor and device id?
77 devicefile romfs-lookup ?dup
79 \ give it a special treatment
82 classfile romfs-lookup ?dup
84 \ give it a pci-class related treatment
87 \ no special handling for this device, attempt autoconfiguration
88 my-space pci-class-name type 2a emit cr
89 my-space pci-device-generic-setup
94 \ Disable Bus Master, Memory Space and I/O Space for this device
95 \ if Bus Master function is needed it should be enabled/disabled by open/close in the device driver code
98 \ Enalbe #PERR and #SERR reporting
101 \ Print out device information
102 my-space 44 pci-out \ config-addr ascii('D')
104 \ and set up the device