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/processor.h>
13 #define ZPCI_INSN_BUSY_DELAY 1 /* 1 microsecond */
15 /* Modify PCI Function Controls */
16 static inline u8
__mpcifc(u64 req
, struct zpci_fib
*fib
, u8
*status
)
21 " .insn rxy,0xe300000000d0,%[req],%[fib]\n"
24 : [cc
] "=d" (cc
), [req
] "+d" (req
), [fib
] "+Q" (*fib
)
26 *status
= req
>> 24 & 0xff;
30 int zpci_mod_fc(u64 req
, struct zpci_fib
*fib
)
35 cc
= __mpcifc(req
, fib
, &status
);
37 msleep(ZPCI_INSN_BUSY_DELAY
);
41 printk_once(KERN_ERR
"%s: error cc: %d status: %d\n",
42 __func__
, cc
, status
);
43 return (cc
) ? -EIO
: 0;
46 /* Refresh PCI Translations */
47 static inline u8
__rpcit(u64 fn
, u64 addr
, u64 range
, u8
*status
)
49 register u64 __addr
asm("2") = addr
;
50 register u64 __range
asm("3") = range
;
54 " .insn rre,0xb9d30000,%[fn],%[addr]\n"
57 : [cc
] "=d" (cc
), [fn
] "+d" (fn
)
58 : [addr
] "d" (__addr
), "d" (__range
)
60 *status
= fn
>> 24 & 0xff;
64 int zpci_refresh_trans(u64 fn
, u64 addr
, u64 range
)
69 cc
= __rpcit(fn
, addr
, range
, &status
);
71 udelay(ZPCI_INSN_BUSY_DELAY
);
75 printk_once(KERN_ERR
"%s: error cc: %d status: %d dma_addr: %Lx size: %Lx\n",
76 __func__
, cc
, status
, addr
, range
);
77 return (cc
) ? -EIO
: 0;
80 /* Set Interruption Controls */
81 void zpci_set_irq_ctrl(u16 ctl
, char *unused
, u8 isc
)
84 " .insn rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n"
85 : : [ctl
] "d" (ctl
), [isc
] "d" (isc
<< 27), [u
] "Q" (*unused
));
89 static inline int __pcilg(u64
*data
, u64 req
, u64 offset
, u8
*status
)
91 register u64 __req
asm("2") = req
;
92 register u64 __offset
asm("3") = offset
;
97 " .insn rre,0xb9d20000,%[data],%[req]\n"
102 : [cc
] "+d" (cc
), [data
] "=d" (__data
), [req
] "+d" (__req
)
105 *status
= __req
>> 24 & 0xff;
112 int zpci_load(u64
*data
, u64 req
, u64 offset
)
118 cc
= __pcilg(data
, req
, offset
, &status
);
120 udelay(ZPCI_INSN_BUSY_DELAY
);
124 printk_once(KERN_ERR
"%s: error cc: %d status: %d req: %Lx offset: %Lx\n",
125 __func__
, cc
, status
, req
, offset
);
126 return (cc
> 0) ? -EIO
: cc
;
128 EXPORT_SYMBOL_GPL(zpci_load
);
131 static inline int __pcistg(u64 data
, u64 req
, u64 offset
, u8
*status
)
133 register u64 __req
asm("2") = req
;
134 register u64 __offset
asm("3") = offset
;
138 " .insn rre,0xb9d00000,%[data],%[req]\n"
143 : [cc
] "+d" (cc
), [req
] "+d" (__req
)
144 : "d" (__offset
), [data
] "d" (data
)
146 *status
= __req
>> 24 & 0xff;
150 int zpci_store(u64 data
, u64 req
, u64 offset
)
156 cc
= __pcistg(data
, req
, offset
, &status
);
158 udelay(ZPCI_INSN_BUSY_DELAY
);
162 printk_once(KERN_ERR
"%s: error cc: %d status: %d req: %Lx offset: %Lx\n",
163 __func__
, cc
, status
, req
, offset
);
164 return (cc
> 0) ? -EIO
: cc
;
166 EXPORT_SYMBOL_GPL(zpci_store
);
168 /* PCI Store Block */
169 static inline int __pcistb(const u64
*data
, u64 req
, u64 offset
, u8
*status
)
174 " .insn rsy,0xeb00000000d0,%[req],%[offset],%[data]\n"
179 : [cc
] "+d" (cc
), [req
] "+d" (req
)
180 : [offset
] "d" (offset
), [data
] "Q" (*data
)
182 *status
= req
>> 24 & 0xff;
186 int zpci_store_block(const u64
*data
, u64 req
, u64 offset
)
192 cc
= __pcistb(data
, req
, offset
, &status
);
194 udelay(ZPCI_INSN_BUSY_DELAY
);
198 printk_once(KERN_ERR
"%s: error cc: %d status: %d req: %Lx offset: %Lx\n",
199 __func__
, cc
, status
, req
, offset
);
200 return (cc
> 0) ? -EIO
: cc
;
202 EXPORT_SYMBOL_GPL(zpci_store_block
);