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