1c6557e7fSMartin Schwidefsky /* 2*4dcc2a4dSSebastian Ott * Copyright IBM Corp. 2007, 2012 3c6557e7fSMartin Schwidefsky * Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com> 4c6557e7fSMartin Schwidefsky */ 5c6557e7fSMartin Schwidefsky 6c6557e7fSMartin Schwidefsky #ifndef _ASM_S390_CHPID_H 787d2f5e3SDavid Howells #define _ASM_S390_CHPID_H 8c6557e7fSMartin Schwidefsky 9c6557e7fSMartin Schwidefsky #include <linux/string.h> 100680ba01SHeiko Carstens #include <linux/types.h> 11c6557e7fSMartin Schwidefsky 12c6557e7fSMartin Schwidefsky #define __MAX_CHPID 255 13c6557e7fSMartin Schwidefsky 14c6557e7fSMartin Schwidefsky struct chp_id { 15*4dcc2a4dSSebastian Ott __u8 reserved1; 16*4dcc2a4dSSebastian Ott __u8 cssid; 17*4dcc2a4dSSebastian Ott __u8 reserved2; 18*4dcc2a4dSSebastian Ott __u8 id; 19c6557e7fSMartin Schwidefsky } __attribute__((packed)); 20c6557e7fSMartin Schwidefsky 21c6557e7fSMartin Schwidefsky #ifdef __KERNEL__ 22c6557e7fSMartin Schwidefsky #include <asm/cio.h> 23c6557e7fSMartin Schwidefsky 24c6557e7fSMartin Schwidefsky static inline void chp_id_init(struct chp_id *chpid) 25c6557e7fSMartin Schwidefsky { 26c6557e7fSMartin Schwidefsky memset(chpid, 0, sizeof(struct chp_id)); 27c6557e7fSMartin Schwidefsky } 28c6557e7fSMartin Schwidefsky 29c6557e7fSMartin Schwidefsky static inline int chp_id_is_equal(struct chp_id *a, struct chp_id *b) 30c6557e7fSMartin Schwidefsky { 31c6557e7fSMartin Schwidefsky return (a->id == b->id) && (a->cssid == b->cssid); 32c6557e7fSMartin Schwidefsky } 33c6557e7fSMartin Schwidefsky 34c6557e7fSMartin Schwidefsky static inline void chp_id_next(struct chp_id *chpid) 35c6557e7fSMartin Schwidefsky { 36c6557e7fSMartin Schwidefsky if (chpid->id < __MAX_CHPID) 37c6557e7fSMartin Schwidefsky chpid->id++; 38c6557e7fSMartin Schwidefsky else { 39c6557e7fSMartin Schwidefsky chpid->id = 0; 40c6557e7fSMartin Schwidefsky chpid->cssid++; 41c6557e7fSMartin Schwidefsky } 42c6557e7fSMartin Schwidefsky } 43c6557e7fSMartin Schwidefsky 44c6557e7fSMartin Schwidefsky static inline int chp_id_is_valid(struct chp_id *chpid) 45c6557e7fSMartin Schwidefsky { 46c6557e7fSMartin Schwidefsky return (chpid->cssid <= __MAX_CSSID); 47c6557e7fSMartin Schwidefsky } 48c6557e7fSMartin Schwidefsky 49c6557e7fSMartin Schwidefsky 50c6557e7fSMartin Schwidefsky #define chp_id_for_each(c) \ 51c6557e7fSMartin Schwidefsky for (chp_id_init(c); chp_id_is_valid(c); chp_id_next(c)) 52c6557e7fSMartin Schwidefsky #endif /* __KERNEL */ 53c6557e7fSMartin Schwidefsky 54c6557e7fSMartin Schwidefsky #endif /* _ASM_S390_CHPID_H */ 55