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