Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / pci-device.fs
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
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
13 get-node CONSTANT my-phandle
14
15 \ get the PUID from the node above
16 s" my-puid" my-phandle parent $call-static CONSTANT my-puid
17
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 ;
22
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 ;
27
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 ;
30
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
35 : open
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
42         true
43 ;
44
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
49 : close 
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
54 ;
55
56 s" dma-function.fs" included
57
58 \ generate the rom-fs filename from the vendor and device ID "pci-device_VENDORID_DEVICEID.fs"
59 : devicefile ( -- str len )
60   s" pci-device_"
61   my-space pci-vendor@ 4 int2str $cat
62   s" _" $cat
63   my-space pci-device@ 4 int2str $cat
64   s" .fs" $cat
65 ;
66
67 \ generate the rom-fs filename from the base-class id "pci-class_BASECLASS.fs"
68 : classfile ( -- str len )
69   s" pci-class_"
70   my-space pci-class@ 10 rshift 2 int2str $cat
71   s" .fs" $cat
72 ;
73
74 \ Set up the device with either default or special settings
75 : setup ( -- )
76         \ is there special handling for this device, given vendor and device id?
77         devicefile romfs-lookup ?dup
78                 IF
79                         \ give it a special treatment
80                         evaluate
81                 ELSE
82                         classfile romfs-lookup ?dup
83                         IF
84                             \ give it a pci-class related treatment
85                             evaluate
86                         ELSE
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
90                         THEN
91                 THEN
92 ;
93
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
96 pci-device-disable
97
98 \ Enalbe #PERR and #SERR reporting
99 pci-error-enable
100
101 \ Print out device information
102 my-space 44 pci-out     \ config-addr ascii('D')
103
104 \ and set up the device
105 setup