2 * s390 PCI instructions
4 * Copyright 2014 IBM Corp.
5 * Author(s): Frank Blaschka <frank.blaschka@de.ibm.com>
6 * Hong Bo Li <lihbbj@cn.ibm.com>
7 * Yi Min Zhao <zyimin@cn.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or (at
10 * your option) any later version. See the COPYING file in the top-level
14 #include "qemu/osdep.h"
15 #include "qemu-common.h"
17 #include "s390-pci-inst.h"
18 #include "s390-pci-bus.h"
19 #include "exec/memory-internal.h"
20 #include "qemu/error-report.h"
22 /* #define DEBUG_S390PCI_INST */
23 #ifdef DEBUG_S390PCI_INST
24 #define DPRINTF(fmt, ...) \
25 do { fprintf(stderr, "s390pci-inst: " fmt, ## __VA_ARGS__); } while (0)
27 #define DPRINTF(fmt, ...) \
31 static void s390_set_status_code(CPUS390XState
*env
,
32 uint8_t r
, uint64_t status_code
)
34 env
->regs
[r
] &= ~0xff000000ULL
;
35 env
->regs
[r
] |= (status_code
& 0xff) << 24;
38 static int list_pci(ClpReqRspListPci
*rrb
, uint8_t *cc
)
40 S390PCIBusDevice
*pbdev
= NULL
;
41 uint32_t res_code
, initial_l2
, g_l2
;
43 uint64_t resume_token
;
46 if (lduw_p(&rrb
->request
.hdr
.len
) != 32) {
47 res_code
= CLP_RC_LEN
;
52 if ((ldl_p(&rrb
->request
.fmt
) & CLP_MASK_FMT
) != 0) {
53 res_code
= CLP_RC_FMT
;
58 if ((ldl_p(&rrb
->request
.fmt
) & ~CLP_MASK_FMT
) != 0 ||
59 ldq_p(&rrb
->request
.reserved1
) != 0) {
60 res_code
= CLP_RC_RESNOT0
;
65 resume_token
= ldq_p(&rrb
->request
.resume_token
);
68 pbdev
= s390_pci_find_dev_by_idx(resume_token
);
70 res_code
= CLP_RC_LISTPCI_BADRT
;
75 pbdev
= s390_pci_find_next_avail_dev(NULL
);
78 if (lduw_p(&rrb
->response
.hdr
.len
) < 48) {
84 initial_l2
= lduw_p(&rrb
->response
.hdr
.len
);
85 if ((initial_l2
- LIST_PCI_HDR_LEN
) % sizeof(ClpFhListEntry
)
87 res_code
= CLP_RC_LEN
;
93 stl_p(&rrb
->response
.fmt
, 0);
94 stq_p(&rrb
->response
.reserved1
, 0);
95 stl_p(&rrb
->response
.mdd
, FH_MASK_SHM
);
96 stw_p(&rrb
->response
.max_fn
, PCI_MAX_FUNCTIONS
);
97 rrb
->response
.flags
= UID_CHECKING_ENABLED
;
98 rrb
->response
.entry_size
= sizeof(ClpFhListEntry
);
101 g_l2
= LIST_PCI_HDR_LEN
;
102 while (g_l2
< initial_l2
&& pbdev
) {
103 stw_p(&rrb
->response
.fh_list
[i
].device_id
,
104 pci_get_word(pbdev
->pdev
->config
+ PCI_DEVICE_ID
));
105 stw_p(&rrb
->response
.fh_list
[i
].vendor_id
,
106 pci_get_word(pbdev
->pdev
->config
+ PCI_VENDOR_ID
));
107 /* Ignore RESERVED devices. */
108 stl_p(&rrb
->response
.fh_list
[i
].config
,
109 pbdev
->state
== ZPCI_FS_STANDBY
? 0 : 1 << 31);
110 stl_p(&rrb
->response
.fh_list
[i
].fid
, pbdev
->fid
);
111 stl_p(&rrb
->response
.fh_list
[i
].fh
, pbdev
->fh
);
113 g_l2
+= sizeof(ClpFhListEntry
);
114 /* Add endian check for DPRINTF? */
115 DPRINTF("g_l2 %d vendor id 0x%x device id 0x%x fid 0x%x fh 0x%x\n",
117 lduw_p(&rrb
->response
.fh_list
[i
].vendor_id
),
118 lduw_p(&rrb
->response
.fh_list
[i
].device_id
),
119 ldl_p(&rrb
->response
.fh_list
[i
].fid
),
120 ldl_p(&rrb
->response
.fh_list
[i
].fh
));
121 pbdev
= s390_pci_find_next_avail_dev(pbdev
);
128 resume_token
= pbdev
->fh
& FH_MASK_INDEX
;
130 stq_p(&rrb
->response
.resume_token
, resume_token
);
131 stw_p(&rrb
->response
.hdr
.len
, g_l2
);
132 stw_p(&rrb
->response
.hdr
.rsp
, CLP_RC_OK
);
135 DPRINTF("list pci failed rc 0x%x\n", rc
);
136 stw_p(&rrb
->response
.hdr
.rsp
, res_code
);
141 int clp_service_call(S390CPU
*cpu
, uint8_t r2
)
145 S390PCIBusDevice
*pbdev
;
148 uint8_t buffer
[4096 * 2];
150 CPUS390XState
*env
= &cpu
->env
;
153 cpu_synchronize_state(CPU(cpu
));
155 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
156 program_interrupt(env
, PGM_PRIVILEGED
, 4);
160 if (s390_cpu_virt_mem_read(cpu
, env
->regs
[r2
], r2
, buffer
, sizeof(*reqh
))) {
163 reqh
= (ClpReqHdr
*)buffer
;
164 req_len
= lduw_p(&reqh
->len
);
165 if (req_len
< 16 || req_len
> 8184 || (req_len
% 8 != 0)) {
166 program_interrupt(env
, PGM_OPERAND
, 4);
170 if (s390_cpu_virt_mem_read(cpu
, env
->regs
[r2
], r2
, buffer
,
171 req_len
+ sizeof(*resh
))) {
174 resh
= (ClpRspHdr
*)(buffer
+ req_len
);
175 res_len
= lduw_p(&resh
->len
);
176 if (res_len
< 8 || res_len
> 8176 || (res_len
% 8 != 0)) {
177 program_interrupt(env
, PGM_OPERAND
, 4);
180 if ((req_len
+ res_len
) > 8192) {
181 program_interrupt(env
, PGM_OPERAND
, 4);
185 if (s390_cpu_virt_mem_read(cpu
, env
->regs
[r2
], r2
, buffer
,
186 req_len
+ res_len
)) {
191 stw_p(&resh
->rsp
, CLP_RC_LEN
);
195 switch (lduw_p(&reqh
->cmd
)) {
197 ClpReqRspListPci
*rrb
= (ClpReqRspListPci
*)buffer
;
201 case CLP_SET_PCI_FN
: {
202 ClpReqSetPci
*reqsetpci
= (ClpReqSetPci
*)reqh
;
203 ClpRspSetPci
*ressetpci
= (ClpRspSetPci
*)resh
;
205 pbdev
= s390_pci_find_dev_by_fh(ldl_p(&reqsetpci
->fh
));
207 stw_p(&ressetpci
->hdr
.rsp
, CLP_RC_SETPCIFN_FH
);
211 switch (reqsetpci
->oc
) {
212 case CLP_SET_ENABLE_PCI_FN
:
213 switch (reqsetpci
->ndas
) {
215 stw_p(&ressetpci
->hdr
.rsp
, CLP_RC_SETPCIFN_DMAAS
);
220 stw_p(&ressetpci
->hdr
.rsp
, CLP_RC_SETPCIFN_RES
);
224 if (pbdev
->fh
& FH_MASK_ENABLE
) {
225 stw_p(&ressetpci
->hdr
.rsp
, CLP_RC_SETPCIFN_FHOP
);
229 pbdev
->fh
|= FH_MASK_ENABLE
;
230 pbdev
->state
= ZPCI_FS_ENABLED
;
231 stl_p(&ressetpci
->fh
, pbdev
->fh
);
232 stw_p(&ressetpci
->hdr
.rsp
, CLP_RC_OK
);
234 case CLP_SET_DISABLE_PCI_FN
:
235 if (!(pbdev
->fh
& FH_MASK_ENABLE
)) {
236 stw_p(&ressetpci
->hdr
.rsp
, CLP_RC_SETPCIFN_FHOP
);
239 device_reset(DEVICE(pbdev
));
240 pbdev
->fh
&= ~FH_MASK_ENABLE
;
241 pbdev
->state
= ZPCI_FS_DISABLED
;
242 stl_p(&ressetpci
->fh
, pbdev
->fh
);
243 stw_p(&ressetpci
->hdr
.rsp
, CLP_RC_OK
);
246 DPRINTF("unknown set pci command\n");
247 stw_p(&ressetpci
->hdr
.rsp
, CLP_RC_SETPCIFN_FHOP
);
252 case CLP_QUERY_PCI_FN
: {
253 ClpReqQueryPci
*reqquery
= (ClpReqQueryPci
*)reqh
;
254 ClpRspQueryPci
*resquery
= (ClpRspQueryPci
*)resh
;
256 pbdev
= s390_pci_find_dev_by_fh(ldl_p(&reqquery
->fh
));
258 DPRINTF("query pci no pci dev\n");
259 stw_p(&resquery
->hdr
.rsp
, CLP_RC_SETPCIFN_FH
);
263 for (i
= 0; i
< PCI_BAR_COUNT
; i
++) {
264 uint32_t data
= pci_get_long(pbdev
->pdev
->config
+
265 PCI_BASE_ADDRESS_0
+ (i
* 4));
267 stl_p(&resquery
->bar
[i
], data
);
268 resquery
->bar_size
[i
] = pbdev
->pdev
->io_regions
[i
].size
?
269 ctz64(pbdev
->pdev
->io_regions
[i
].size
) : 0;
270 DPRINTF("bar %d addr 0x%x size 0x%" PRIx64
"barsize 0x%x\n", i
,
271 ldl_p(&resquery
->bar
[i
]),
272 pbdev
->pdev
->io_regions
[i
].size
,
273 resquery
->bar_size
[i
]);
276 stq_p(&resquery
->sdma
, ZPCI_SDMA_ADDR
);
277 stq_p(&resquery
->edma
, ZPCI_EDMA_ADDR
);
278 stl_p(&resquery
->fid
, pbdev
->fid
);
279 stw_p(&resquery
->pchid
, 0);
280 stw_p(&resquery
->ug
, 1);
281 stl_p(&resquery
->uid
, pbdev
->uid
);
282 stw_p(&resquery
->hdr
.rsp
, CLP_RC_OK
);
285 case CLP_QUERY_PCI_FNGRP
: {
286 ClpRspQueryPciGrp
*resgrp
= (ClpRspQueryPciGrp
*)resh
;
288 stq_p(&resgrp
->dasm
, 0);
289 stq_p(&resgrp
->msia
, ZPCI_MSI_ADDR
);
290 stw_p(&resgrp
->mui
, 0);
291 stw_p(&resgrp
->i
, 128);
294 stw_p(&resgrp
->hdr
.rsp
, CLP_RC_OK
);
298 DPRINTF("unknown clp command\n");
299 stw_p(&resh
->rsp
, CLP_RC_CMD
);
304 if (s390_cpu_virt_mem_write(cpu
, env
->regs
[r2
], r2
, buffer
,
305 req_len
+ res_len
)) {
312 int pcilg_service_call(S390CPU
*cpu
, uint8_t r1
, uint8_t r2
)
314 CPUS390XState
*env
= &cpu
->env
;
315 S390PCIBusDevice
*pbdev
;
324 cpu_synchronize_state(CPU(cpu
));
326 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
327 program_interrupt(env
, PGM_PRIVILEGED
, 4);
332 program_interrupt(env
, PGM_SPECIFICATION
, 4);
336 fh
= env
->regs
[r2
] >> 32;
337 pcias
= (env
->regs
[r2
] >> 16) & 0xf;
338 len
= env
->regs
[r2
] & 0xf;
339 offset
= env
->regs
[r2
+ 1];
341 pbdev
= s390_pci_find_dev_by_fh(fh
);
343 DPRINTF("pcilg no pci dev\n");
344 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
348 switch (pbdev
->state
) {
349 case ZPCI_FS_RESERVED
:
350 case ZPCI_FS_STANDBY
:
351 case ZPCI_FS_DISABLED
:
352 case ZPCI_FS_PERMANENT_ERROR
:
353 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
356 setcc(cpu
, ZPCI_PCI_LS_ERR
);
357 s390_set_status_code(env
, r2
, ZPCI_PCI_ST_BLOCKED
);
364 if ((8 - (offset
& 0x7)) < len
) {
365 program_interrupt(env
, PGM_OPERAND
, 4);
368 mr
= pbdev
->pdev
->io_regions
[pcias
].memory
;
369 result
= memory_region_dispatch_read(mr
, offset
, &data
, len
,
370 MEMTXATTRS_UNSPECIFIED
);
371 if (result
!= MEMTX_OK
) {
372 program_interrupt(env
, PGM_OPERAND
, 4);
375 } else if (pcias
== 15) {
376 if ((4 - (offset
& 0x3)) < len
) {
377 program_interrupt(env
, PGM_OPERAND
, 4);
380 data
= pci_host_config_read_common(
381 pbdev
->pdev
, offset
, pci_config_size(pbdev
->pdev
), len
);
387 data
= bswap16(data
);
390 data
= bswap32(data
);
393 data
= bswap64(data
);
396 program_interrupt(env
, PGM_OPERAND
, 4);
400 DPRINTF("invalid space\n");
401 setcc(cpu
, ZPCI_PCI_LS_ERR
);
402 s390_set_status_code(env
, r2
, ZPCI_PCI_ST_INVAL_AS
);
406 env
->regs
[r1
] = data
;
407 setcc(cpu
, ZPCI_PCI_LS_OK
);
411 static void update_msix_table_msg_data(S390PCIBusDevice
*pbdev
, uint64_t offset
,
412 uint64_t *data
, uint8_t len
)
417 if (offset
% PCI_MSIX_ENTRY_SIZE
!= 8) {
422 DPRINTF("access msix table msg data but len is %d\n", len
);
426 msg_data
= (uint8_t *)data
- offset
% PCI_MSIX_ENTRY_SIZE
+
427 PCI_MSIX_ENTRY_VECTOR_CTRL
;
428 val
= pci_get_long(msg_data
) |
429 ((pbdev
->fh
& FH_MASK_INDEX
) << ZPCI_MSI_VEC_BITS
);
430 pci_set_long(msg_data
, val
);
431 DPRINTF("update msix msg_data to 0x%" PRIx64
"\n", *data
);
434 static int trap_msix(S390PCIBusDevice
*pbdev
, uint64_t offset
, uint8_t pcias
)
436 if (pbdev
->msix
.available
&& pbdev
->msix
.table_bar
== pcias
&&
437 offset
>= pbdev
->msix
.table_offset
&&
438 offset
<= pbdev
->msix
.table_offset
+
439 (pbdev
->msix
.entries
- 1) * PCI_MSIX_ENTRY_SIZE
) {
446 int pcistg_service_call(S390CPU
*cpu
, uint8_t r1
, uint8_t r2
)
448 CPUS390XState
*env
= &cpu
->env
;
449 uint64_t offset
, data
;
450 S390PCIBusDevice
*pbdev
;
457 cpu_synchronize_state(CPU(cpu
));
459 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
460 program_interrupt(env
, PGM_PRIVILEGED
, 4);
465 program_interrupt(env
, PGM_SPECIFICATION
, 4);
469 fh
= env
->regs
[r2
] >> 32;
470 pcias
= (env
->regs
[r2
] >> 16) & 0xf;
471 len
= env
->regs
[r2
] & 0xf;
472 offset
= env
->regs
[r2
+ 1];
474 pbdev
= s390_pci_find_dev_by_fh(fh
);
476 DPRINTF("pcistg no pci dev\n");
477 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
481 switch (pbdev
->state
) {
482 case ZPCI_FS_RESERVED
:
483 case ZPCI_FS_STANDBY
:
484 case ZPCI_FS_DISABLED
:
485 case ZPCI_FS_PERMANENT_ERROR
:
486 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
489 setcc(cpu
, ZPCI_PCI_LS_ERR
);
490 s390_set_status_code(env
, r2
, ZPCI_PCI_ST_BLOCKED
);
496 data
= env
->regs
[r1
];
498 if ((8 - (offset
& 0x7)) < len
) {
499 program_interrupt(env
, PGM_OPERAND
, 4);
503 if (trap_msix(pbdev
, offset
, pcias
)) {
504 offset
= offset
- pbdev
->msix
.table_offset
;
505 mr
= &pbdev
->pdev
->msix_table_mmio
;
506 update_msix_table_msg_data(pbdev
, offset
, &data
, len
);
508 mr
= pbdev
->pdev
->io_regions
[pcias
].memory
;
511 result
= memory_region_dispatch_write(mr
, offset
, data
, len
,
512 MEMTXATTRS_UNSPECIFIED
);
513 if (result
!= MEMTX_OK
) {
514 program_interrupt(env
, PGM_OPERAND
, 4);
517 } else if (pcias
== 15) {
518 if ((4 - (offset
& 0x3)) < len
) {
519 program_interrupt(env
, PGM_OPERAND
, 4);
526 data
= bswap16(data
);
529 data
= bswap32(data
);
532 data
= bswap64(data
);
535 program_interrupt(env
, PGM_OPERAND
, 4);
539 pci_host_config_write_common(pbdev
->pdev
, offset
,
540 pci_config_size(pbdev
->pdev
),
543 DPRINTF("pcistg invalid space\n");
544 setcc(cpu
, ZPCI_PCI_LS_ERR
);
545 s390_set_status_code(env
, r2
, ZPCI_PCI_ST_INVAL_AS
);
549 setcc(cpu
, ZPCI_PCI_LS_OK
);
553 int rpcit_service_call(S390CPU
*cpu
, uint8_t r1
, uint8_t r2
)
555 CPUS390XState
*env
= &cpu
->env
;
557 S390PCIBusDevice
*pbdev
;
562 cpu_synchronize_state(CPU(cpu
));
564 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
565 program_interrupt(env
, PGM_PRIVILEGED
, 4);
570 program_interrupt(env
, PGM_SPECIFICATION
, 4);
574 fh
= env
->regs
[r1
] >> 32;
575 start
= env
->regs
[r2
];
576 end
= start
+ env
->regs
[r2
+ 1];
578 pbdev
= s390_pci_find_dev_by_fh(fh
);
580 DPRINTF("rpcit no pci dev\n");
581 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
585 switch (pbdev
->state
) {
586 case ZPCI_FS_RESERVED
:
587 case ZPCI_FS_STANDBY
:
588 case ZPCI_FS_DISABLED
:
589 case ZPCI_FS_PERMANENT_ERROR
:
590 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
593 setcc(cpu
, ZPCI_PCI_LS_ERR
);
594 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_ERROR_RECOVER
);
600 if (!pbdev
->g_iota
) {
601 pbdev
->state
= ZPCI_FS_ERROR
;
602 setcc(cpu
, ZPCI_PCI_LS_ERR
);
603 s390_set_status_code(env
, r1
, ZPCI_PCI_ST_INSUF_RES
);
604 s390_pci_generate_error_event(ERR_EVENT_INVALAS
, pbdev
->fh
, pbdev
->fid
,
609 if (end
< pbdev
->pba
|| start
> pbdev
->pal
) {
610 pbdev
->state
= ZPCI_FS_ERROR
;
611 setcc(cpu
, ZPCI_PCI_LS_ERR
);
612 s390_set_status_code(env
, r1
, ZPCI_PCI_ST_INSUF_RES
);
613 s390_pci_generate_error_event(ERR_EVENT_OORANGE
, pbdev
->fh
, pbdev
->fid
,
618 mr
= &pbdev
->iommu_mr
;
619 while (start
< end
) {
620 entry
= mr
->iommu_ops
->translate(mr
, start
, 0);
622 if (!entry
.translated_addr
) {
623 pbdev
->state
= ZPCI_FS_ERROR
;
624 setcc(cpu
, ZPCI_PCI_LS_ERR
);
625 s390_set_status_code(env
, r1
, ZPCI_PCI_ST_INSUF_RES
);
626 s390_pci_generate_error_event(ERR_EVENT_SERR
, pbdev
->fh
, pbdev
->fid
,
627 start
, ERR_EVENT_Q_BIT
);
631 memory_region_notify_iommu(mr
, entry
);
632 start
+= entry
.addr_mask
+ 1;
635 setcc(cpu
, ZPCI_PCI_LS_OK
);
640 int pcistb_service_call(S390CPU
*cpu
, uint8_t r1
, uint8_t r3
, uint64_t gaddr
,
643 CPUS390XState
*env
= &cpu
->env
;
644 S390PCIBusDevice
*pbdev
;
653 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
654 program_interrupt(env
, PGM_PRIVILEGED
, 6);
658 fh
= env
->regs
[r1
] >> 32;
659 pcias
= (env
->regs
[r1
] >> 16) & 0xf;
660 len
= env
->regs
[r1
] & 0xff;
663 DPRINTF("pcistb invalid space\n");
664 setcc(cpu
, ZPCI_PCI_LS_ERR
);
665 s390_set_status_code(env
, r1
, ZPCI_PCI_ST_INVAL_AS
);
676 program_interrupt(env
, PGM_SPECIFICATION
, 6);
680 pbdev
= s390_pci_find_dev_by_fh(fh
);
682 DPRINTF("pcistb no pci dev fh 0x%x\n", fh
);
683 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
687 switch (pbdev
->state
) {
688 case ZPCI_FS_RESERVED
:
689 case ZPCI_FS_STANDBY
:
690 case ZPCI_FS_DISABLED
:
691 case ZPCI_FS_PERMANENT_ERROR
:
692 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
695 setcc(cpu
, ZPCI_PCI_LS_ERR
);
696 s390_set_status_code(env
, r1
, ZPCI_PCI_ST_BLOCKED
);
702 mr
= pbdev
->pdev
->io_regions
[pcias
].memory
;
703 if (!memory_region_access_valid(mr
, env
->regs
[r3
], len
, true)) {
704 program_interrupt(env
, PGM_OPERAND
, 6);
708 if (s390_cpu_virt_mem_read(cpu
, gaddr
, ar
, buffer
, len
)) {
712 for (i
= 0; i
< len
/ 8; i
++) {
713 result
= memory_region_dispatch_write(mr
, env
->regs
[r3
] + i
* 8,
714 ldq_p(buffer
+ i
* 8), 8,
715 MEMTXATTRS_UNSPECIFIED
);
716 if (result
!= MEMTX_OK
) {
717 program_interrupt(env
, PGM_OPERAND
, 6);
722 setcc(cpu
, ZPCI_PCI_LS_OK
);
726 static int reg_irqs(CPUS390XState
*env
, S390PCIBusDevice
*pbdev
, ZpciFib fib
)
730 ret
= css_register_io_adapter(S390_PCIPT_ADAPTER
,
731 FIB_DATA_ISC(ldl_p(&fib
.data
)), true, false,
732 &pbdev
->routes
.adapter
.adapter_id
);
735 pbdev
->summary_ind
= get_indicator(ldq_p(&fib
.aisb
), sizeof(uint64_t));
736 len
= BITS_TO_LONGS(FIB_DATA_NOI(ldl_p(&fib
.data
))) * sizeof(unsigned long);
737 pbdev
->indicator
= get_indicator(ldq_p(&fib
.aibv
), len
);
739 ret
= map_indicator(&pbdev
->routes
.adapter
, pbdev
->summary_ind
);
744 ret
= map_indicator(&pbdev
->routes
.adapter
, pbdev
->indicator
);
749 pbdev
->routes
.adapter
.summary_addr
= ldq_p(&fib
.aisb
);
750 pbdev
->routes
.adapter
.summary_offset
= FIB_DATA_AISBO(ldl_p(&fib
.data
));
751 pbdev
->routes
.adapter
.ind_addr
= ldq_p(&fib
.aibv
);
752 pbdev
->routes
.adapter
.ind_offset
= FIB_DATA_AIBVO(ldl_p(&fib
.data
));
753 pbdev
->isc
= FIB_DATA_ISC(ldl_p(&fib
.data
));
754 pbdev
->noi
= FIB_DATA_NOI(ldl_p(&fib
.data
));
755 pbdev
->sum
= FIB_DATA_SUM(ldl_p(&fib
.data
));
757 DPRINTF("reg_irqs adapter id %d\n", pbdev
->routes
.adapter
.adapter_id
);
760 release_indicator(&pbdev
->routes
.adapter
, pbdev
->summary_ind
);
761 release_indicator(&pbdev
->routes
.adapter
, pbdev
->indicator
);
762 pbdev
->summary_ind
= NULL
;
763 pbdev
->indicator
= NULL
;
767 int pci_dereg_irqs(S390PCIBusDevice
*pbdev
)
769 release_indicator(&pbdev
->routes
.adapter
, pbdev
->summary_ind
);
770 release_indicator(&pbdev
->routes
.adapter
, pbdev
->indicator
);
772 pbdev
->summary_ind
= NULL
;
773 pbdev
->indicator
= NULL
;
774 pbdev
->routes
.adapter
.summary_addr
= 0;
775 pbdev
->routes
.adapter
.summary_offset
= 0;
776 pbdev
->routes
.adapter
.ind_addr
= 0;
777 pbdev
->routes
.adapter
.ind_offset
= 0;
782 DPRINTF("dereg_irqs adapter id %d\n", pbdev
->routes
.adapter
.adapter_id
);
786 static int reg_ioat(CPUS390XState
*env
, S390PCIBusDevice
*pbdev
, ZpciFib fib
)
788 uint64_t pba
= ldq_p(&fib
.pba
);
789 uint64_t pal
= ldq_p(&fib
.pal
);
790 uint64_t g_iota
= ldq_p(&fib
.iota
);
791 uint8_t dt
= (g_iota
>> 2) & 0x7;
792 uint8_t t
= (g_iota
>> 11) & 0x1;
794 if (pba
> pal
|| pba
< ZPCI_SDMA_ADDR
|| pal
> ZPCI_EDMA_ADDR
) {
795 program_interrupt(env
, PGM_OPERAND
, 6);
799 /* currently we only support designation type 1 with translation */
800 if (!(dt
== ZPCI_IOTA_RTTO
&& t
)) {
801 error_report("unsupported ioat dt %d t %d", dt
, t
);
802 program_interrupt(env
, PGM_OPERAND
, 6);
808 pbdev
->g_iota
= g_iota
;
810 s390_pci_iommu_enable(pbdev
);
815 void pci_dereg_ioat(S390PCIBusDevice
*pbdev
)
817 s390_pci_iommu_disable(pbdev
);
823 int mpcifc_service_call(S390CPU
*cpu
, uint8_t r1
, uint64_t fiba
, uint8_t ar
)
825 CPUS390XState
*env
= &cpu
->env
;
829 S390PCIBusDevice
*pbdev
;
830 uint64_t cc
= ZPCI_PCI_LS_OK
;
832 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
833 program_interrupt(env
, PGM_PRIVILEGED
, 6);
837 oc
= env
->regs
[r1
] & 0xff;
838 dmaas
= (env
->regs
[r1
] >> 16) & 0xff;
839 fh
= env
->regs
[r1
] >> 32;
842 program_interrupt(env
, PGM_SPECIFICATION
, 6);
846 pbdev
= s390_pci_find_dev_by_fh(fh
);
848 DPRINTF("mpcifc no pci dev fh 0x%x\n", fh
);
849 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
853 switch (pbdev
->state
) {
854 case ZPCI_FS_RESERVED
:
855 case ZPCI_FS_STANDBY
:
856 case ZPCI_FS_DISABLED
:
857 case ZPCI_FS_PERMANENT_ERROR
:
858 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
864 if (s390_cpu_virt_mem_read(cpu
, fiba
, ar
, (uint8_t *)&fib
, sizeof(fib
))) {
869 program_interrupt(env
, PGM_OPERAND
, 6);
874 case ZPCI_MOD_FC_REG_INT
:
875 if (pbdev
->summary_ind
) {
876 cc
= ZPCI_PCI_LS_ERR
;
877 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_SEQUENCE
);
878 } else if (reg_irqs(env
, pbdev
, fib
)) {
879 cc
= ZPCI_PCI_LS_ERR
;
880 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_RES_NOT_AVAIL
);
883 case ZPCI_MOD_FC_DEREG_INT
:
884 if (!pbdev
->summary_ind
) {
885 cc
= ZPCI_PCI_LS_ERR
;
886 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_SEQUENCE
);
888 pci_dereg_irqs(pbdev
);
891 case ZPCI_MOD_FC_REG_IOAT
:
893 cc
= ZPCI_PCI_LS_ERR
;
894 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_DMAAS_INVAL
);
895 } else if (pbdev
->iommu_enabled
) {
896 cc
= ZPCI_PCI_LS_ERR
;
897 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_SEQUENCE
);
898 } else if (reg_ioat(env
, pbdev
, fib
)) {
899 cc
= ZPCI_PCI_LS_ERR
;
900 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_INSUF_RES
);
903 case ZPCI_MOD_FC_DEREG_IOAT
:
905 cc
= ZPCI_PCI_LS_ERR
;
906 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_DMAAS_INVAL
);
907 } else if (!pbdev
->iommu_enabled
) {
908 cc
= ZPCI_PCI_LS_ERR
;
909 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_SEQUENCE
);
911 pci_dereg_ioat(pbdev
);
914 case ZPCI_MOD_FC_REREG_IOAT
:
916 cc
= ZPCI_PCI_LS_ERR
;
917 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_DMAAS_INVAL
);
918 } else if (!pbdev
->iommu_enabled
) {
919 cc
= ZPCI_PCI_LS_ERR
;
920 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_SEQUENCE
);
922 pci_dereg_ioat(pbdev
);
923 if (reg_ioat(env
, pbdev
, fib
)) {
924 cc
= ZPCI_PCI_LS_ERR
;
925 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_INSUF_RES
);
929 case ZPCI_MOD_FC_RESET_ERROR
:
930 switch (pbdev
->state
) {
931 case ZPCI_FS_BLOCKED
:
933 pbdev
->state
= ZPCI_FS_ENABLED
;
936 cc
= ZPCI_PCI_LS_ERR
;
937 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_SEQUENCE
);
940 case ZPCI_MOD_FC_RESET_BLOCK
:
941 switch (pbdev
->state
) {
943 pbdev
->state
= ZPCI_FS_BLOCKED
;
946 cc
= ZPCI_PCI_LS_ERR
;
947 s390_set_status_code(env
, r1
, ZPCI_MOD_ST_SEQUENCE
);
950 case ZPCI_MOD_FC_SET_MEASURE
:
951 pbdev
->fmb_addr
= ldq_p(&fib
.fmb_addr
);
954 program_interrupt(&cpu
->env
, PGM_OPERAND
, 6);
955 cc
= ZPCI_PCI_LS_ERR
;
962 int stpcifc_service_call(S390CPU
*cpu
, uint8_t r1
, uint64_t fiba
, uint8_t ar
)
964 CPUS390XState
*env
= &cpu
->env
;
968 S390PCIBusDevice
*pbdev
;
970 uint64_t cc
= ZPCI_PCI_LS_OK
;
972 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
973 program_interrupt(env
, PGM_PRIVILEGED
, 6);
977 fh
= env
->regs
[r1
] >> 32;
978 dmaas
= (env
->regs
[r1
] >> 16) & 0xff;
981 setcc(cpu
, ZPCI_PCI_LS_ERR
);
982 s390_set_status_code(env
, r1
, ZPCI_STPCIFC_ST_INVAL_DMAAS
);
987 program_interrupt(env
, PGM_SPECIFICATION
, 6);
991 pbdev
= s390_pci_find_dev_by_idx(fh
& FH_MASK_INDEX
);
993 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
997 memset(&fib
, 0, sizeof(fib
));
999 switch (pbdev
->state
) {
1000 case ZPCI_FS_RESERVED
:
1001 case ZPCI_FS_STANDBY
:
1002 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
1004 case ZPCI_FS_DISABLED
:
1005 if (fh
& FH_MASK_ENABLE
) {
1006 setcc(cpu
, ZPCI_PCI_LS_INVAL_HANDLE
);
1010 /* BLOCKED bit is set to one coincident with the setting of ERROR bit.
1011 * FH Enabled bit is set to one in states of ENABLED, BLOCKED or ERROR. */
1014 case ZPCI_FS_BLOCKED
:
1016 case ZPCI_FS_ENABLED
:
1018 if (pbdev
->iommu_enabled
) {
1021 if (!(fh
& FH_MASK_ENABLE
)) {
1022 env
->regs
[r1
] |= 1ULL << 63;
1025 case ZPCI_FS_PERMANENT_ERROR
:
1026 setcc(cpu
, ZPCI_PCI_LS_ERR
);
1027 s390_set_status_code(env
, r1
, ZPCI_STPCIFC_ST_PERM_ERROR
);
1031 stq_p(&fib
.pba
, pbdev
->pba
);
1032 stq_p(&fib
.pal
, pbdev
->pal
);
1033 stq_p(&fib
.iota
, pbdev
->g_iota
);
1034 stq_p(&fib
.aibv
, pbdev
->routes
.adapter
.ind_addr
);
1035 stq_p(&fib
.aisb
, pbdev
->routes
.adapter
.summary_addr
);
1036 stq_p(&fib
.fmb_addr
, pbdev
->fmb_addr
);
1038 data
= ((uint32_t)pbdev
->isc
<< 28) | ((uint32_t)pbdev
->noi
<< 16) |
1039 ((uint32_t)pbdev
->routes
.adapter
.ind_offset
<< 8) |
1040 ((uint32_t)pbdev
->sum
<< 7) | pbdev
->routes
.adapter
.summary_offset
;
1041 stl_p(&fib
.data
, data
);
1044 if (s390_cpu_virt_mem_write(cpu
, fiba
, ar
, (uint8_t *)&fib
, sizeof(fib
))) {