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