2 * s390 specific pci instructions
4 * Copyright IBM Corp. 2013
7 #include <linux/export.h>
8 #include <linux/errno.h>
9 #include <linux/delay.h>
10 #include <asm/pci_insn.h>
11 #include <asm/pci_debug.h>
12 #include <asm/processor.h>
14 #define ZPCI_INSN_BUSY_DELAY 1 /* 1 microsecond */
16 static inline void zpci_err_insn(u8 cc
, u8 status
, u64 req
, u64 offset
)
23 } __packed data
= {req
, offset
, cc
, status
};
25 zpci_err_hex(&data
, sizeof(data
));
28 /* Modify PCI Function Controls */
29 static inline u8
__mpcifc(u64 req
, struct zpci_fib
*fib
, u8
*status
)
34 " .insn rxy,0xe300000000d0,%[req],%[fib]\n"
37 : [cc
] "=d" (cc
), [req
] "+d" (req
), [fib
] "+Q" (*fib
)
39 *status
= req
>> 24 & 0xff;
43 int zpci_mod_fc(u64 req
, struct zpci_fib
*fib
)
48 cc
= __mpcifc(req
, fib
, &status
);
50 msleep(ZPCI_INSN_BUSY_DELAY
);
54 zpci_err_insn(cc
, status
, req
, 0);
56 return (cc
) ? -EIO
: 0;
59 /* Refresh PCI Translations */
60 static inline u8
__rpcit(u64 fn
, u64 addr
, u64 range
, u8
*status
)
62 register u64 __addr
asm("2") = addr
;
63 register u64 __range
asm("3") = range
;
67 " .insn rre,0xb9d30000,%[fn],%[addr]\n"
70 : [cc
] "=d" (cc
), [fn
] "+d" (fn
)
71 : [addr
] "d" (__addr
), "d" (__range
)
73 *status
= fn
>> 24 & 0xff;
77 int zpci_refresh_trans(u64 fn
, u64 addr
, u64 range
)
82 cc
= __rpcit(fn
, addr
, range
, &status
);
84 udelay(ZPCI_INSN_BUSY_DELAY
);
88 zpci_err_insn(cc
, status
, addr
, range
);
90 return (cc
) ? -EIO
: 0;
93 /* Set Interruption Controls */
94 void zpci_set_irq_ctrl(u16 ctl
, char *unused
, u8 isc
)
97 " .insn rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n"
98 : : [ctl
] "d" (ctl
), [isc
] "d" (isc
<< 27), [u
] "Q" (*unused
));
102 static inline int __pcilg(u64
*data
, u64 req
, u64 offset
, u8
*status
)
104 register u64 __req
asm("2") = req
;
105 register u64 __offset
asm("3") = offset
;
110 " .insn rre,0xb9d20000,%[data],%[req]\n"
115 : [cc
] "+d" (cc
), [data
] "=d" (__data
), [req
] "+d" (__req
)
118 *status
= __req
>> 24 & 0xff;
125 int zpci_load(u64
*data
, u64 req
, u64 offset
)
131 cc
= __pcilg(data
, req
, offset
, &status
);
133 udelay(ZPCI_INSN_BUSY_DELAY
);
137 zpci_err_insn(cc
, status
, req
, offset
);
139 return (cc
> 0) ? -EIO
: cc
;
141 EXPORT_SYMBOL_GPL(zpci_load
);
144 static inline int __pcistg(u64 data
, u64 req
, u64 offset
, u8
*status
)
146 register u64 __req
asm("2") = req
;
147 register u64 __offset
asm("3") = offset
;
151 " .insn rre,0xb9d00000,%[data],%[req]\n"
156 : [cc
] "+d" (cc
), [req
] "+d" (__req
)
157 : "d" (__offset
), [data
] "d" (data
)
159 *status
= __req
>> 24 & 0xff;
163 int zpci_store(u64 data
, u64 req
, u64 offset
)
169 cc
= __pcistg(data
, req
, offset
, &status
);
171 udelay(ZPCI_INSN_BUSY_DELAY
);
175 zpci_err_insn(cc
, status
, req
, offset
);
177 return (cc
> 0) ? -EIO
: cc
;
179 EXPORT_SYMBOL_GPL(zpci_store
);
181 /* PCI Store Block */
182 static inline int __pcistb(const u64
*data
, u64 req
, u64 offset
, u8
*status
)
187 " .insn rsy,0xeb00000000d0,%[req],%[offset],%[data]\n"
192 : [cc
] "+d" (cc
), [req
] "+d" (req
)
193 : [offset
] "d" (offset
), [data
] "Q" (*data
)
195 *status
= req
>> 24 & 0xff;
199 int zpci_store_block(const u64
*data
, u64 req
, u64 offset
)
205 cc
= __pcistb(data
, req
, offset
, &status
);
207 udelay(ZPCI_INSN_BUSY_DELAY
);
211 zpci_err_insn(cc
, status
, req
, offset
);
213 return (cc
> 0) ? -EIO
: cc
;
215 EXPORT_SYMBOL_GPL(zpci_store_block
);